Environment set up

  1. JDK download and configure environment variables
  2. SDK download and configure environment variables
  3. GIT downloads and configures environment variables
  4. Jenkins download and install.

This article focuses on how to configure Jenkins. The first three configurations will not be described in detail. Please refer to Baidu for details.

Set up steps

Check that environment variables are configured correctly.

1. Check environment variables

Win Run CMD and enter

java -version
Copy the code

Check whether Java version is displayed. If the output is successful, JDK configuration is correct.

Win Run CMD and enter

adb start-server
Copy the code

Check whether ADB Server is successfully started. If yes, the SDK is successfully configured

Win Run CMD and enter

git
Copy the code

If git Usage is displayed, the configuration is successful

  1. Unpack the toolkit and follow the wizard to install Jenkins. Install the plug-in recommended by the wizard. After installing the Plugin, check whether the Android Lint Plugin, Gradle Plugin, and Git Plugin are installed in the installed list.

  2. Configure Jenkins’ global tool configuration

  • Enter the Homepage of Jenkin, as shown below, and click System Management.

Find the global tool configuration

  1. Configure the JDK

  1. Git configuration

  1. Gradle configuration

Note: The gradle version configured here must be consistent with the project being built. In addition, the path should not be too long, otherwise it will cause errors in AAPT (it is recommended to move the corresponding gradle version to the root directory of a disk, or directly use the built-in gradle of the project to download it during compilation).

  1. The following figure shows the global SDK path

Go to System Administration on the left and click system Settings as shown in the image below

Find the environment variable configuration, add the Android Sdk configuration, == path need to change your Sdk path ==

Create a task without parameters

  1. A new task

  2. To add a description, click Advanced Settings to configure the workspace

  3. Configure the code git repository

  1. The build

Configuration GradleWrapper

Configure the root build script path

Create a task with parameters

  1. Create a free-style build project as with the no-input task
  2. Choose a parameterized build process

  1. Build parameters, as obtained in build.gradle.

As shown in the figure above, take option parameters and text parameters for example. You can use “${parameterName}” for parameters defined in Jenkins, for example, when Jenkins selects a branch:

How do I get the corresponding parameters in the Andrid project? The JAR_VERSION_NAME can be obtained from build.gradle in the app package name as follows:

def defaultName = "2.04.11"
def jarVersionName = project.hasProperty('JAR_VERSION_NAME')? JAR_VERSION_NAME : defaultNameCopy the code

Note: The Boolean parameter is replaced by the option parameter, which gets inaccurate when run in Gradle3.3.

def needNewsSdk = project.hasProperty('NEED_NEWS_SDK')? NEED_NEWS_SDK :"false"
boolean isNeedNewsSdk = needNewsSdk == "true"
Copy the code
  1. The other procedures are the same as the no-parameter task, and the parameters need to be carried to the command when executing the Gradle script.
clean
assembleRelease -PJAR_VERSION_NAME=${JAR_VERSION_NAME} }
Copy the code

Note: Parameter names are used-PTo begin,PAs the capital

After the build, build other projects, with parameters.

  1. Plug-ins need to be installedParameterized Trigger pluginIn the system Administration-Plugin-Management-installable options section, retrieve this plugin to install and restart Jenkins/restart)
  2. In the build or post-build options (the location of this plugin varies depending on Jenkins version), find:

Fill in the name of the next project to build and add parameters. You can select the parameters of the current task as shown above.

other

Jenkins Toolkit download: Click download

Extract password: 3ZR5