首先在创建前,把这些插件先装上:
Build With Parameters
Parameterized Scheduler
Parameterized Trigger plugin
Persistent Parameter Plugin```
创建pipeline项目:
![1.PNG](https://img.haomeiwen.com/i4687469/d1fbbd8fef4e5964.PNG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
创建好之后点击配置:进去之后点参数化构建:
![2.PNG](https://img.haomeiwen.com/i4687469/d887d4cc0d99a277.PNG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
上面的"p1"以及“job”后面可以单变量用,然后到最下面配置pipeline:
![3.PNG](https://img.haomeiwen.com/i4687469/096f050be3a51ceb.PNG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
代码如下:
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building'
echo "${p1}"
build "${job}" #构建项目,用build 'jobname'
build 'freestyle1'
build 'freestyle2'
load '333' #这个经过测试,load这个文件可以读出里面的内容
}
}
stage('Test') {
steps {
echo 'Testing..'
echo "${env.JOB_NAME}" #这个是打印出当前job名字。
}
}
stage('Deploy') {
steps {
echo 'Deploying....'
}
}
}
}
配置完成后可以执行了,点击Build with Parameters,会出现如下界面让你选择:
![4.png](https://img.haomeiwen.com/i4687469/ba9b8ce77f1c7be7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
执行结果为:
```Started by user ljb[Pipeline] nodeRunning on master in /var/jenkins_home/workspace/pipeline-1[Pipeline] {[Pipeline] stage[Pipeline] { (Build)[Pipeline] echoBuilding[Pipeline] echo2[Pipeline] build (Building freestyle1)Scheduling project: freestyle1Starting building: freestyle1 #20[Pipeline] load[Pipeline] { (333)[Pipeline] echo333333[Pipeline] }[Pipeline] // load[Pipeline] fileExists[Pipeline] }[Pipeline] // stage[Pipeline] stage[Pipeline] { (Test)[Pipeline] echoTesting..[Pipeline] echopipeline-1[Pipeline] }[Pipeline] // stage[Pipeline] stage[Pipeline] { (Deploy)[Pipeline] echoDeploying....[Pipeline] }[Pipeline] // stage[Pipeline] }[Pipeline] // node[Pipeline] End of PipelineFinished: SUCCESS```
所以这个比较适合严格要求法办顺序的job,比如:a1,a2,a3,a4,a5依次发版本,这个就比较合适
接下来是对于非pipeline的job添加build with Parameters,下面的是自由风格的job:
![5.png](https://img.haomeiwen.com/i4687469/cf167f1fde6d5f86.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
选了参数化构建之后,构建按钮就变成了build with Parameters,点击build with Parameters后,就给发送版本加上了版本好了:
![6.png](https://img.haomeiwen.com/i4687469/785d7653e577d722.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
初次之外,还何以设置用户认证构建,可以有效保护重要项目!
网友评论