Jenkins Pipline语法
Posted presley-lpc
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Jenkins Pipline语法相关的知识,希望对你有一定的参考价值。
引用自:http://baijiahao.baidu.com/s?id=1582812185263227836&wfr=spider&for=pc
引用自:https://www.cnblogs.com/YatHo/p/7856556.html
一、多参数选择
pipeline{
agent {
label ‘192.168.0.156‘
}
parameters{
choice(name:‘test‘,
choices:‘test_a
test_b‘,
description:‘this is test‘)
}
environment{
b = "/bbb"
}
stages{
stage(‘阶段1‘){
steps{
script{
a = "/home"
sh "pwd"
sh "echo "test1""
sh "echo ${test}"
}
}
}
stage(‘阶段2‘){
steps{
script{
sh "echo "test2""
sh "echo ${a}"
sh "echo ${b}"
}
}
}
stage(‘阶段3‘){
steps{
script{
sh "echo "test3""
}
}
}
stage(‘阶段4‘){
steps{
script{
sh "echo "test4""
}
}
}
}
}
2、单参数选择
pipeline {
agent {
label ‘192.168.0.156‘
}
options {
timeout(time: 30, unit: ‘MINUTES‘)
}
parameters {
//构建选项,选择构建环境
choice(name: ‘release_env‘,
choices:‘pro‘,
description: ‘choose release environment
server:47.98.172.183
pro port:4564‘)
}
stages {
stage(‘准备源码‘) {
steps {
script {
// 类似项目执行更改以下两个参数
svn_addr="svn://192.168.0.151/pycf/Projects/fof2.0/fof2.0-product_daily_data"
module_name="product_daily_data"
workdir="/application/docker_hub/java/fof2"
project_name="fof2"
r_env=release_env
docker_file_path="${workdir}/${module_name}_${r_env}"
docker_compose_file="${workdir}/docker-compose-${r_env}.yml"
docker_compose_module_name="${project_name}_${module_name}_${r_env}"
}
checkout([$class: ‘SubversionSCM‘,
additionalCredentials: [],
excludedCommitMessages: ‘‘,
excludedRegions: ‘‘,
excludedRevprop: ‘‘,
excludedUsers: ‘‘,
filterChangelog: false,
ignoreDirPropChanges: false,
includedRegions: ‘‘,
locations: [[credentialsId: ‘dffd18a8-473e-477e-a4dc-4d528fa3e55c‘,
depthOption: ‘infinity‘,
ignoreExternalsOption: true,
local: ‘.‘,
remote: svn_addr ]],
quietOperation: true,
workspaceUpdater: [$class: ‘UpdateUpdater‘]])
}
}
stage(‘构建运行‘) {
steps {
sh "mkdir -p ${docker_file_path}; rm -rf ${docker_file_path}/*"
sh "/bin/cp -a ./* ${docker_file_path};"
sh "echo ‘svn url: ${svn_addr}‘ > ${docker_file_path}/README.txt"
sh "svn upgrade . &> /dev/null||echo &> /dev/null"
sh "export LANG=en_US.UTF-8;svn info . 2>/dev/null|grep -i Revision|awk ‘{print "svn revision: "$2}‘ >> ${docker_file_path}/README.txt"
sh "echo ‘jenkins job: ${env.JOB_NAME}‘ >> ${docker_file_path}/README.txt"
sh "echo ‘jenkins build env: ${r_env}‘ >> ${docker_file_path}/README.txt"
sh "echo ‘jenkins build number: ${env.BUILD_NUMBER}‘ >> ${docker_file_path}/README.txt"
sh "cd /application/docker_hub/fof2.0-deploy/;/usr/bin/python main.py 10 yes;"
}
}
stage(‘等待30s检查业务‘) {
steps {
script {
sh "sleep 30;"
sh " cd /application/docker_hub/fof2.0-deploy/;/usr/bin/python check.py ${docker_compose_module_name};"
}
}
}
}
}
以上是关于Jenkins Pipline语法的主要内容,如果未能解决你的问题,请参考以下文章
jenkins结合gitlab实现pipline的自动构建部署