下面是pipeline项目的配置:
1.png点击build with parameters:
2.png点击开始构建:
3.png构建成狗,我们来看下控制台输出日志:
Started by user ljb[Pipeline] propertiesWARNING: The properties step will remove all JobPropertys currently configured in this job, either from the UI or from an earlier properties step.This includes configuration for discarding old builds, parameters, concurrent builds and build triggers.WARNING: Removing existing job property '参数化构建过程'WARNING: Removing existing job property 'Build triggers'[Pipeline] nodeRunning on master in /root/.jenkins/workspace/pipeline[Pipeline] {[Pipeline] stage[Pipeline] { (Build)[Pipeline] echohello demaxiya,66666[Pipeline] echoBuilding[Pipeline] input是否要部署?Proceed or AbortApproved by ljb[Pipeline] echodemaxiya,66666[Pipeline] fileExists[Pipeline] timestamps[Pipeline] {[Pipeline] echo16:19:26 tttttttt[Pipeline] }[Pipeline] // timestamps[Pipeline] }[Pipeline] // stage[Pipeline] stage[Pipeline] { (Test)[Pipeline] echoTesting..[Pipeline] echopipeline[Pipeline] }[Pipeline] // stage[Pipeline] stage[Pipeline] { (Deploy)[Pipeline] echoDeploying....[Pipeline] }[Pipeline] // stage[Pipeline] }[Pipeline] // node[Pipeline] End of PipelineFinished: SUCCESS
成功了。上面的其实还可以根据输出判断你要去执行线上环境还是测试环境还是dev环境,只需要在下面的脚本上加上相应的语句都可以实现。下面是我的pipeline script的语句:
pipeline {
agent any
parameters {
string(name: 'yyyyy', defaultValue: 'demaxiya', description: 'gggggg')
}
stages {
stage('Build') {
steps {
echo "hello ${params.yyyyy}" //此处调用了上面的参数化构建哪里的给的值,可以获取到
echo 'Building'
input '再次确认是否要部署?' //点击Build with Parameters按钮之后会出现是否继续执行,再次确认是否要部署
//build "${p1}" //部署选择的项目
echo "${yyyyy}"
// sh '/bin/bash 111.sh' //执行此项目下面的111.sh脚本
fileExists './555'
//cleanWs(patterns: [[pattern: 'aaaa', type: 'EXCLUDE']]) //删除当前工作目录下的所有文件,保留aaaa文件
timestamps { //天假时间戳,可以清楚看到几点几分做的什么动作
echo 'tttttttt'
}
}
}
stage('Test') {
steps {
echo 'Testing..'
echo "${env.JOB_NAME}"
}
}
stage('Deploy') {
steps {
echo 'Deploying....'
}
}
}
网友评论