@TOC

One, Jenkins overview

Jenkins is a popular open source Continuous Integration tool, widely used in project development, with automated build, test, and deployment capabilities. Jenkins originated in Hudson (which is commercial) and was primarily used for continuous, automated building/testing of software projects and monitoring the execution of external tasks. Jenkins is written in the Java language and can run in popular servlet containers such as Tomcat or on its own. It is often used in combination with version management tools (SCM) and build tools. Common version control tools include SVN and GIT, and build tools include Maven, Ant, and Gradle.

Two, Jenkins installation

1. DownloadJenkins’s official website

2. Install the JDK/Maven

Export JAVA_HOME = / usr/Java/jdk1.8.0 _111 export MAVEN_HOME = / opt/apache maven -- 3.3.9Copy the code
  • Four installation modes:
  1. Offline installation
## http://pkg.jenkins-ci.org/redhat/Wget http://pkg.jenkins-ci.org/redhat/jenkins-2.39-1.1.noarch.rpm ## download sudo RPM --import http://pkg.jenkins-ci.org/redhat/jenkins.io.key # # public key sudo yum - y install Jenkins - *. Noarch. RPMCopy the code
  1. Online installation
## http://pkg.jenkins-ci.org/redhat/
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key
sudo yum -y install jenkins


Copy the code
  1. Installation Based on Tomcat
  • Install and start Tomcat;
  • Download Jenkins. War from the official website to $CATALINA_BASE/webapps, Tomcat will automatically deploy;
  • Browser visit: http://centos:8080/jenkins/
  1. Installation free
Wget http://mirrors.jenkins.io/war-stable/latest/jenkins.war sudo Java - jar jenkens. War # # start the service, Until you see log 'Jenkins is fully up and running' curl http://localhost:8080/ ## Jenkins is readyCopy the code

3. Adjust the configuration file

## sudo vim /etc/sysconfig/jenkinsJENKINS_PORT="8080" ## JENKINS_PORT="8080" #### enable HTTPS


Copy the code

Installation directory: /usr/lib/Jenkins Working directory: /var/lib/Jenkins (corresponding to the environment variable JENKINS_HOME)

4. Start

sudo systemctl enable jenkins
sudo systemctl restart jenkins

Copy the code

To view the log file: sudo tail -f/var/log/Jenkins Jenkins. Log

After start-up will be generated file Hudson. Model. UpdateCenter. XML, need to modify it, otherwise the browser for the first time they enter card in “Jenkins is starting, please later…”

## original value: http://updates.jenkins-ci.org/update-center.json
## new value: http://mirror.xmission.com/jenkins/updates/update-center.json
## 或者: http://mirror.xmission.com/jenkins/updates/current/update-center.json
sudo cat /var/lib/jenkins/hudson.model.UpdateCenter.xml
sudo sed -i 's/updates.jenkins-ci.org/mirror.xmission.com\/jenkins\/updates/g' /var/lib/jenkins/hudson.model.UpdateCenter.xml
sudo cat /var/lib/jenkins/hudson.model.UpdateCenter.xml
sudo systemctl restart jenkins

Copy the code

5. Permit the firewall

### sudo vim /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
#Sudo systemctl restart iptables

Copy the code

6. Uninstall

If you want to reinstall Jenkins, or the unit does not need Jenkins, uninstall:

sudo systemctl stop jenkins
sudo systemctl disable jenkins
sudo yum -y remove jenkins
sudo rm -rf /var/{lib,log,cache}/jenkins /usr/lib/jenkins /root/.jenkins
sudo rm -rf `sudo find /{etc,var,run} -name "jenkins*"`

Copy the code

7. Install on a MAC

  • Install Jenkins using homebrew that comes with OSX
  1. You need to have java1.8 installed, if not, you will be prompted to download itjdk1.8
  2. With Java installed, proceed to link the Launchd configuration file
$ ln -sfv/usr/local/opt/jenkins/*.plist ~/Library/LaunchAgents  // If you want other machines to access it, change the IP address to broadcast address :--httpListenAddress=0.0.0.0$ launchctl load~/Library/LaunchAgents/homebrew.mxcl.jenkins.plist
Copy the code
  1. Command line to start Jenkins
$ jenkins
Copy the code
  1. If all goes well, open your browser and type http://localhost:8080/ to see that Jenkins is up and running, and if you change the port you set later.

Next, after Jenkins is opened, there will be a page for filling in the password as shown in the picture below. The place where the password is stored is in the red font directory on the picture. You can see it by using terminal CAT + red font path

Then input the password we obtained into the “Administrator Password”, you can enter the following interface, and then install some recommended plug-ins (left). During the installation process, some plug-ins may fail to be installed, it is strongly recommended to click the lower right corner to retry until the recommended installation is complete. (Because I failed to install Jenkins plugins in Jenkins plugins management after installation. If I failed to install some necessary plugins in this step, such as Git, it would be very troublesome to download and upload plugins one by one.)

Register in the refreshed interface and enter the user name and password. You are advised to click the blue button to save the Settings as follows:

Third, Jenkins configuration

1. Login

Browser go to http://centos:8080/ for the first time into the need to enter the initial password to unlock, initial password check methods: sudo cat/var/lib/Jenkins/secrets/initialAdminPassword

2. Security Settings

By default, any user can post using Jenkins. System Administration/Configure Global Security, select Jenkins proprietary user database, do not select Allow user registration. Select Allow Anonymous Read Access for login users to do anything

3. Plug-in installation method

  • Offline installation: Manual download (*.hpi): updates.jenkins-ci.org/download/pl… Go to: System Administration/Management plug-ins/Advanced, and then upload the plug-in for installation. No need to restart the Jenkins plugin to take effect.
  • Online installation: Go to system management/Management plug-ins/Optional plug-ins Find and select the required plug-ins, and click Install directly. No need to restart the Jenkins plugin to take effect. If the installation fails, try again or go offline.

4. Set tools

To: System management/Global Tool Configuration JDK do not select Automatic installation, specify the alias =JDK-1.8.0.111, and do not select Automatic installation in JAVA_HOME=/usr/ Java /jdk1.8.0_111. Specify alias = maven-3.3.9, MAVEN_HOME=/opt/apache-maven-3.3.9 and click the Save button. The command takes effect after Jenkins restart: sudo systemctl restart Jenkins

5. Install the Plug-in required for ios packaging

  1. Keychains and Provisioning Profiles Management plugins for managing local Keychain and iOS certificates
  2. For Xcode to build Xcode Integration

Installation method: Solution 1: Search for the plug-in name and select Install. If an installation error occurs (refer to Jenkins Installation failure to install plug-ins online to solve the problem), if not, go directly to Plan 2.

6. Configure IOS before packaging

  1. Provisioning Keychains and Provisioning Profiles Management Choose Keychains and Provisioning Profiles Management in order

    You need to upload the login.keychain file. To obtain the file, enter:

cd ~/Library/Keychains
Copy the code

Type LS on the terminal as shown in the following figure

  1. Configure the task and then create a task, free style task, because there will be two build methods, in addition to the common areas, the build will be divided into two parts of the solution, the first part is the build method before Mac OS10.12, but due to Jenkins’ Xcode and Mac system version issues, the second method is recommended.

Create a free-style task, then choose to discard the old build, as required by the number of days and the maximum number to keep, as shown in the figure

  • Source code management

Git: Support for mainstream Github and GitLab code repositories. Since our research and development team uses GitLab, I will only describe it below. Repository URL: indicates the Repository address. Credentials: indicates the Credentials. The user name and password can be HTTP or RSA file. But ADD the credentials through the “ADD” button at the end. The Branches to build. */master Indicates the master branch. It can also be set to another branch. Source browser: the repository management tools you use, such as github, gitlab. URL: fill in the repository address at the top. This is the Version of our GitLab server. Subversion: SVN.

Add your git address to the Repository URL. If your project uses SSH, Add your git address to the Repository URL. If your project uses SSH, Add your SSH key to the Repository URL. Specific oneself baidu once good cough up, I did not write much, the result is shown

  • Build triggers A build trigger, as its name implies, is a trigger for a build task

Build after other projects are built: This option means “Build after other projects are built”. This option is not covered here, but may be used later.

Periodically: Build periodically. It’s a good idea to build every once in a while. The calendar format is similar to the Linux Crontab format. The Settings in the figure below represent a build every 30 minutes.

Build when a change is pushed to the GitLab code repository, i.e. trigger the Build. This is followed by an address that triggers the build, commonly referred to as Webhooks. This address needs to be configured into Gitlab, how webhooks do this is described later. This is a common build trigger.

Poll SCM: This option is used in conjunction with the above option. Jenkins doesn’t know when the code repository changes. This option needs to be configured periodically to check for changes to the code repository.

Build a trigger, that is, when to trigger automatic packing I fill out here is this means H H * * * 20 hours then, followed by the Numbers, is behind the sun, * representing is triggered each time, I think, that is, every month every year, but Jenkins time is not absolute, are generally in random in half, That is, if set to 20, it will trigger at about 20:30. If two times are needed, the format can be H 20,22 * * *. The result is shown in the figure

  • In the build environment check Keychains and Code Signing and Mobile Provisioning Profiles. Keychains and Code Signing Identities are the certificates that need to be packaged, and Mobile Provisioning Profiles are the Profiles that need to be packaged, which can be selected by themselves

7. IOS is packaged and built

The next step is to build, because Jenkins is not compatible with the new version of Xcode plug-in, can only be packaged with scripts, but the old version of Xcode can use Jenkins Xcode plug-in, the following will build one using Xcode plug-in, the second is script

7.1 Using the Xcode Plug-in

In build click Add Build step, then click Xcode.General Build Settings and enter your project name in Target, Clean before Build and check YES. Check Pack Application, Build and sign.ipa? “, then there will be a new option Export Method is the type of package you want to type, that is, the four options of ad-hoc or Appstore that you selected when manually packing. Fill in this option according to the type you want to type. Ipa filename pattern is the ipA name of the package you want to type. I filled in the project name and -$(BUILD_DATE) here, which means to append time after, Output directory is the directory to export IPA, if you don’t fill in, it will be in Jenkins’ default directory.

Code signing & OS X keychain options In Keychain path there fill in ${HOME} / Library/Keychains/login Keychain, mean to find your login. The Keychain landing (keys), if you copy out to change name, then you fill in the corresponding directory, Keychain Password is the password used to log in to your computer. As shown in the figure

Advanced Xcode Build Options check Clean Test Reports? If you are using Cocoapods then fill in the Xcode Workspace File. If you are not using Cocoapods then fill in the Xcode Project Directory and then fill in the Build Output Directory which is your path around the IPA.

After that, go back to the task operation page and click Build Now. If the configuration is ok, you can basically build successfully.

The profile file does not match the target file, and the target file does not match the target file. The target file does not match the target file, and the target file does not match the target file

7.2 Using Scripts

Jenkins is not compatible with the current Xcode9 plugin, so we use XcodeBuild package. Here is the script:

#! /bin/sh# Since Jenkins packaging may be automatic, the build number will not change itself and then push to Git, so buildPlist is the path to change the build number.

buildPlist="/Users/apple/.jenkins/workspace/longxin_a/eCloud/Build/LongHu/Config/eCloud-Info.plist"  
#This gets the current month and day time and uses it to make the build number
buildNumber=$(date +"%m%d%H%M") 
 #To modify the plist file, run the /usr/libexec/plistbuddy -c command.
# $buildNumberIs the value you want to modify,$buildPlistIs where you modify the PList file.
 /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$buildPlist" 
 #This is used to retrieve the current build number to see if it has been modified successfully#newBuildName=$(/usr/libexec/PlistBuddy -c "print :CFBundleVersion" "$buildPlist")
  #This is print, print with wrap
  echo $newBuildName  
   #Because I was afraid that it would take time for him to modify the plist, I simply made him wait for 3 seconds here. Of course, you can also remove sleep 3
   #This buildPath is where I'll build xCarchive files and where I'll need to find XCarchive for ipA
   buildPath="/Users/apple/.jenkins/workspace/longxin_a/build/Release-iphoneos/eCloud.xcarchive"  
   #So this is the path that I took to generate ipA, ipaPath="/Users/apple/Documents/longhuBuild/" # this is the path to exportOptions. plist, so you don't need to script the certificate. If you have this path, you need to manually package the plist, so you can find it in the folder that generates the IPA, find a place where you don't change it often, and write this path. If you want to set the certificate in the shell language, I will be in problem list have introduced exportOptionsplistPath = '/ Users/apple /. Jenkins/workspace/ExportOptions plist' # since I'm using Cocoapods, I'll use -workspace. If you're not using Cocoapods, I'll use -project. The following command will be the same. /Users/app*** ecloud.xcworkspace path eCloud,  xcodebuild -workspace /Users/apple/.jenkins/workspace/longxin_a/eCloud.xcworkspace -scheme eCloud -configuration "Release" Clean # This is generating XCarchive, Release xcodebuild - workspace/Users/apple /. Jenkins/workspace/longxin_a/eCloud xcworkspace - scheme eCloud - archivePath Xcodebuild-exportarchive-archivepath ${buildPath} -configuration "Release" archive  -exportPath ${ipaPath} -exportOptionsPlist ${exportOptionsplistPath} -allowProvisioningUpdatesCopy the code

8. Email notifications

Jenkins was notified by email. Now you have installed the Email Extension Plugin. This is the first step. Then go to System Administration -> System Settings and locate the Jenkins Location module. In the system administrator email address, fill in your system administrator email address, which is the email from which you send notifications, and locate the Extended E-mail Notification module

Then locate the post-build actions, click add post-build steps, click Editable Email Notification, enter the manager’s Email address in Project From, and click Advanced Setting. There are three options, which are the ones you checked in the system Settings. Fill in the options according to your requirements. I fill in Always, that is, whether the construction succeeds or fails, the RecipientList is the Recipient’s email, and multiple email addresses are separated by English commas.

9. Upload to FIR

  1. Download the FIR plugin first
  2. Select the plug-in you just downloaded and click Upload. After uploading successfully, enter your project configuration and slide to the bottom, that is, find the post-build operation and click Add the post-build operation steps. Select Upload to fir. Im, open your browser, open fir official website, see the picture to obtain the method

10. Change the password

Jenkins password error Remove password login (MAC path is /Users/ username /.jenkins)

Jenkins changes the login password

Jenkins uninstall

11. Configure related parameters

11.1 Configuring the SSH Server
  1. Log in to Jenkins — System Administration — System Settings
  2. SSH Servers: SINCE I have configured the Jenkins server public key file, I only need to configure this item when ADDING SSH Servers. Name: user-defined and globally unique. HostName: indicates the HostName. Use the IP address directly. Username: indicates the Username of the newly added Server. Remote Directory: indicates the Remote Directory. Jenkins server sends files to the new server in this directory by default.

Four, IOS Jenkins pack

Five, Jenkins pack

Wang /2017/01/06/…

Blog.csdn.net/u014641783/…

Blog. X1be. Win/index. PHP / 2…