jenkins
Jenkins is an open source continuous integration tool written in Java. After a dispute with Oracle, engraved items from the Hudson project.
Jenkins provides continuous integration of software development services. It runs in the Servlet container (e.g., Apache Tomcat). It supports software configuration management (SCM) tools (including AccuRev SCM, CVS, Subversion, Git, Perforce, Clearcase and RTC), you can execute the batch command based on Apache Ant and Apache Maven project, and any of Shell scripts and Windows. Jenkins is the main developer Kawaguchi farming referrals. Jenkins is released under the MIT license free software.
It can be triggered by a variety of means to build. Is triggered e.g. submitted to a version control system, may also be constructed when the other has been completed, you can request a particular URL by scheduling mechanism similar to the Cron.
Create a Pipeline
After the basic environment to build good, let's configure a workflow personally feel
Workflow is called pipeline in Jenkins, the pipeline running behavior defined by the user, the content stored in a Jenkinsfile definition file and store the file in the root directory of the git repository, the general process is as follows
- User submitted code to git
- Jenkins pull the latest code from git
- Read Jenkinsfile file in the root directory, and followed by the implementation of tasks defined in the file
The following is a specific configuration steps
Write Jenkinsfile
pipeline {
agent {
label 'master' /* 执行节点 */
}
stages {
stage('Build') {
steps {
echo 'Building'
}
}
stage('Test') {
steps {
echo 'Testing'
}
}
stage('Deploy - Staging') {
steps {
sh './deploy staging'
sh './run-smoke-tests'
}
}
stage('Sanity check') {
steps {
input "Does the staging environment look ok?"
}
}
stage('Deploy - Production') {
steps {
echo './deploy production'
}
}
}复制代码
post {
always {
echo 'One way or another, I have finished'
deleteDir() /* clean up our workspace */
}
success {
echo 'I succeeeded!'
}
unstable {
echo 'I am unstable :/'
}
failure {
echo 'I failed :('
}
changed {
echo 'Things were different before...'
}
}
}
复制代码
The above is a basic Jenkinsfile template, which has the following key concepts
agent
- Specify perform a task on which machine, remember the above configurationNode
, when filledLabel
, and if the twolabel
match was on, in theNode
executedstage
- large steps of the workflow, these serial steps, e.g.build
,test
,deploy
etc.steps
- in small steps described stage, the samestage
insteps
parallelsh
- executeshell
commandinput
- You need to manually click OK,Pipeline
will enter the subsequent links, commonly used in deployment areas, because very often people need to deploy some confirmation ofpost
- After all the pipeline execution is completed, it will link into the post, the link generally do some cleanup work, but also can determine the status of the implementation of the pipeline
After understanding these, you will find write a Jenkinsfile is a very easy thing. Well, now to test pipeline function, the above code into sh echo, copy to your Jenkinsfile, the git repository and stored in the root directory
Create a pipeline
Back to the Jenkins web pages, add pipeline
If every time you want git commit
to automatically execute when the pipeline, there are two ways, one is to allow Jenkins to poll git, git repository per minute checks have not been updated, the following configuration
Another way is to use the git provide the hook, the principle is the way git Once submitted, it will trigger hook in the script, the script Jenkins sent to the instruction execution pipeline, this way is more elegant, but more needs to be done accordingly a little more, there is not a demonstration of this approach, interested students can study their own look.
Finally, we need to set the address git, in which the credit is set, consistent and above said Master credit set to Node
Once set up, once you git repository receives a new submission, it will trigger the running of the pipeline, this figure is running the following state Jenkinsfile the example above, you can see when you run the Sanity check this step, you need to manually trigger whether to perform the operation back.
other
Project address: https: //github.com/changdaye/jenkins-docker-demo/
Step graphical plug presentations: https://wiki.jenkins.io/display/JENKINS/Pipeline+Stage+View+Plugin