preface

In the previous article we detailed how to use Jenkins to automate builds quickly and easily. This time we’re going to talk about some more advanced techniques that you need to learn to use.

When we were building with Jenkins, we certainly ran into the question: there are multiple versions of the project in the cloud, how do you specify which version to build? The first idea was to try to create multiple Jenkins projects, which would solve the problem, but not elegantly enough. We can elegantly solve this problem using parametric builds.

1, the sample

First, let’s look at the final result. The start button for Jenkins builds has been changed from an immediate build to a parameterized build, and two customization options have been added: Branch and Platform. Branch is free to choose which branch to build, while Platform is free to choose whether to submit to Fir or AppStore.

2. Add parameters

Now I show you how to add these two parameters.

2.1. Click “Parameterize the Build Process”

2.2. Add Git Parameters

Click “Add Parameters”, “Git Parameters”. I defined the parameter name as branch, and then refined the branch parameters.

2.3. Add “Option Parameters”

The option parameter is represented as a menu whose contents can be customized. I’m going to set Fir and AppStore here.

In three steps, the parameter definition is complete.

3. Use parameters

Once the parameters are defined, how do you use them?

3.1. Use of branch parameters

We just defined a branch parameter, so when specifying the branch to build, we can fill it in like this:

Then we select the branch from the menu, and the selected information corresponds to the branch.

3.2. Use of platform parameters

Similarly, we also defined the platform parameter. When we decide which platform to upload to (Fir or AppStore), we can fill it in the following way:

If [${platform} == "Fir"] /bin/bash --login fir publish "$WORKSPACE/Export/Fir/*****.ipa" -T "61a07dbfe4a4dc8*****7e57b71e7c93" else if [ ${platform} = = "AppStore"] # upload AppStore then xcrun altool - validate - app - f "$WORKSPACE/Export/AppStore / * * * * *. Ipa" -u *****@gmail.com -p "mhwt-nlzo-****-lokb" -t ios xcrun altool --upload-app -f "$WORKSPACE/Export/AppStore/*****.ipa" -u *****@gmail.com -p "mhwt-nlzo-****-lokb" -t ios fiCopy the code

4, summarize

Is there more that a single project can do by using parametric builds? Completely eliminates the need to create multiple Jenkins projects for one piece of code.

If you’re not familiar with some of the basics, you can go back to the previous article and learn how to automate builds with Jenkins quickly and easily.