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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值