Jenkins – 脚本式流水线示例

注意
脚本式流水线,不创建Jenkinsfile脚本,直接在Jenkins操作界面中输入脚本,这命名很容易让人混淆。

参照Jenkins – 创建流水线任务章节,创建的流水线任务,在流水线配置中,编写脚本。如下图所示:

图

脚本内容:

node {
      for (i=0; i<2; i++) { 
           stage "Stage #"+i
           print 'Hello, world!'
           if (i==0)
           {
               echo 'Running on Stage #0'
           }
           else {
               echo 'Running on Stage #1'
           }
      }
}

执行流水线

阶段视图如下:

图

控制台输出:

Started by user admin
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /root/.jenkins/workspace/qikegu-demo9-pipeline
[Pipeline] {
[Pipeline] stage
Using the ‘stage’ step without a block argument is deprecated
Entering stage Stage #0
Proceeding
[Pipeline] echo
Hello, world!
[Pipeline] echo
Running on Stage #0
[Pipeline] stage
Using the ‘stage’ step without a block argument is deprecated
Entering stage Stage #1
Proceeding
[Pipeline] echo
Hello, world!
[Pipeline] echo
Running on Stage #1
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS


浙ICP备17015664号 浙公网安备 33011002012336号 联系我们 网站地图  
@2019 qikegu.com 版权所有,禁止转载