Jenkins和pipeline
Jenkins
https://jenkins.io/index.html
The leading open source automation server, Jenkins provides hundreds of plugins to support building, deploying and automating any project.
http://www.cnblogs.com/itech/archive/2011/11/23/2260009.html
Jenkins的突出特点:
开源免费;
跨平台,支持所有的平台;
master/slave支持分布式的build;
web形式的可视化的管理页面;
安装配置超级简单;
tips及时快速的帮助;
已有的200多个插件;
Pipeline
https://jenkins.io/doc/book/pipeline/
Jenkins Pipeline is a suite of plugins which supports implementing and integrating continuous delivery pipelines into Jenkins. Pipeline provides an extensible set of tools for modeling simple-to-complex delivery pipelines "as code" via the Pipeline DSL. [1]
Typically, this "Pipeline as Code" would be written to a
Jenkinsfile
and checked into a project’s source control repository, for example:
pipeline { agent any stages { stage('Build') { steps { sh 'make' } } stage('Test'){ steps { sh 'make check' junit 'reports/**/*.xml' } } stage('Deploy') { steps { sh 'make publish' } } } }
典型场景: devops 下载 编译 测试 部署
Parallelism and Distributed Builds with Jenkins
https://www.cloudbees.com/blog/parallelism-and-distributed-builds-jenkins
parallel ( "stream 1" : { ... things ... }, "stream 2" : { ... things in parallel ... } )
https://issues.jenkins-ci.org/browse/JENKINS-33185
for (int i=0; i< 2; ++i) {
stage "Stage #"+i
print 'Hello, world $i!'
}
stage "Stage Parallel"
def branches = [:]
for (int i = 0; i < numHelloMessages.toInteger(); i++) {
branches["split \$ \{i\}"] = {
stage "Stage paralle l - #" + i
node('remote') {
echo 'Starting sleep'
sleep 10
echo 'Finished sleep'
}
}
}
parallel branches
Jenkins file样例库
https://github.com/jenkinsci/pipeline-examples/blob/master/pipeline-examples/jobs-in-parallel/jobs_in_parallel.groovy
// in this array we'll place the jobs that we wish to run
def branches = [:]
//running the job 4 times concurrently
//the dummy parameter is for preventing mutation of the parameter before the execution of the closure.
//we have to assign it outside the closure or it will run the job multiple times with the same parameter "4"
//and jenkins will unite them into a single run of the job
for (int i = 0; i < 4; i++) {
def index = i //if we tried to use i below, it would equal 4 in each job execution.
branches["branch${i}"] = {
//Parameters:
//param1 : an example string parameter for the triggered job.
//dummy: a parameter used to prevent triggering the job with the same parameters value. this parameter has to accept a different value
//each time the job is triggered.
build job: 'test_jobs', parameters: [[$class: 'StringParameterValue', name: 'param1', value:
'test_param'], [$class: 'StringParameterValue', name:'dummy', value: "${index}"]]
}
}
parallel branches