preface

Every time package to test engineering for testing, compile on computer -> export IPA -> upload SVN -> inform the tester. Each iteration is repeated work. As an efficient coder, I looked for an automatic tool to help me do this, and then I came up with the scheme in this paper.

Set up

Install Jenkins

Jenkins needs to rely on Java and need to download JDK. After installing JDK, you can download the War package from Jenkins’ official website.

JDK Download Portal Jenkins download portal

Download the WAR and put it in a path you like, then enter the directory and run the startup command, you can customize the port number to start, the command is as follows

java -jar jenkins.war --httpPort=8888Copy the code

After booting, open the browser and enter http://localhost:8888. The password needs to be reset after booting for the first time. Jenkins’ default configuration directory

The cat ~ /. Jenkins/secrets/initialAdminPasswordCopy the code

Copy the password into the input box to log in, and then set the account password, select some plug-ins. If offline is displayed, skip the plug-in selection and go directly to the home page. To solve the problem of not obtaining the plug-in list, you can go to system Administration -> Plug-in Management -> Advanced -> Upgrade site and change the site to http://updates.jenkins-ci.org/update-center.json to obtain the plug-in list.

I just installed the Generic Webhook Trigger plug-in. Search for the plugins you want to install and install them.

This completes the Jenkins tool configuration.

The configuration of Gogs

I’m using Gogs for code hosting. If you use SVN for code management, you can baidu, there are many related tutorials.

Set up webhook in git repository.

Because we are Jenkins installation webhook plug-in receiving address is http://192.168.1.91:8888/generic-webhook-trigger/invoke? Token =< token filled on Jenkins >

Choose to receive data in JSON format and only trigger push time.

Configuring Jenkins Tasks

A new task

Fill in the project name for the corresponding code. There is a choice between building a free-style software project to reconfigure, or copying an existing task to configure. Then click OK.

Configuration tasks

  • general

    You can check to discard old builds.

  • Source code management

    Select Git, add the URL of the project, and add the corresponding Git account. The branch name is $ref. Why do I fill this out? I’ll explain that in a second. The branch name is for Jenkins to build with that branch. Clean before checkout, Check out to specific local branch, and name **.

  • Build trigger

    The JSON format of the Gogs push can be viewed here at the portal. Some fields are as follows. If you’re not using Gogs, go to the website for the corresponding tool.

    The REF field is a branch of the push event. We can use this field to distinguish branches that need to be built automatically. For example, the Develop branch doesn’t need to be built, the Master branch does.

    The token fills in the project name that uniquely identifies the job. Remember not to duplicate it. Check the Generic Webhook Trigger and add post Content Parameters, an environment variable named for the job, that can be referenced elsewhere in the job as $***, such as $ref. Expression Selects Jsonpath and uses the Jsonpath syntax to match the field name. The Optional filter is used to distinguish between those that trigger the build. The branch name is used to distinguish whether or not to build. I use the regular ^ \ S * release | beta | alpha $to listen only on release, beta, alpha three branches, according to own actual situation to modify here.

  • build

    You could have installed the Xcode plug-in to build it, but configuring the Xcode plug-in was a bit of a hassle, so I gave up and used shell scripts instead, which gave me a great deal of customization. Xcode plugins can be customized. Part of the script is as follows.

    configuration="Release"
    
    ipa_version=$(git symbolic-ref --short -q HEAD)
    
    bundle_version=""
    if [[ $ipa_version = 'alpha' ]]; then
        configuration="Debug"
        bundle_version=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" $infopl_path)
    elif [[ $ipa_version = 'beta' ]]; then
        configuration="Release"
        bundle_version=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" $infopl_path)
    elif [[ $ipa_version = 'release' ]]; then
        configuration="Release"
        bundle_version=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" $infopl_path)
    else
        exit 0
    fi
    
    archivePath="${BUILD_PATH}/${ipa_version}/${JOB_NAME}.xcarchive"
    
    tempPath="${BUILD_PATH}/${ipa_version}/temp"
    
    xcodebuild clean -scheme $JOB_NAME -configuration $configuration
    projectPath=$(find $WORKSPACE  -name "*.xcworkspace" -maxdepth 1)
    
    if [[ -n $projectPath ]]; then
        xcodebuild archive -workspace ./${JOB_NAME}.xcworkspace/ -scheme ${JOB_NAME} -archivePath ${archivePath} -configuration $configuration
    else
        projectPath=$(find $WORKSPACE  -name "*.xcodeproj" -maxdepth 1)
        xcodebuild archive -project $projectPath -scheme ${JOB_NAME} -archivePath ${archivePath} -configuration $configuration
    fi
    
    xcodebuild -exportArchive -archivePath ${archivePath} -exportPath ${tempPath} -exportOptionsPlist ${exportOptionsPlist}Copy the code

    Xcode8 will need to provide exportOptionsPlist when exporting IPA using XcodeBuild. Export the plist content of development, AD-Hot, AppStore is a little different, you can manually export the corresponding package, there will be exportOptionsPlist, refer to it.

  • After the build is complete

    You can upload it to FTP or distribute it to dandelions, and then send an email to the appropriate person to let them know. I did all of this in the build script. You can also use some of Jenkins’ plugins to help you.

The last

I hope this article can help some students.