pipeline{ agent any environment { def git_url = "###" def appdir= "###" def localAppRoot = "###" def stagingip="###" def furl="###" } stages{ stage('clear dir'){ steps{ echo "clear dir" sh ''' #!/bin/bash -xe rm -rf ./* ''' } } stage('pull code and config'){ steps{ echo "checkout from git" sh "git clone ${git_url}" } } stage('compile and package'){ steps{ echo "compile and package" sh ''' cd ${localAppRoot} mvn clean package -DskipTests ''' #获取当前代码的最新commit id, 并且url 跳转当前commit id对应的代码仓库 script{ result = sh(script: "cd ${localAppRoot} && git rev-parse HEAD", returnStdout: true).trim() currentBuild.displayName="#${BUILD_ID}-${result}" currentBuild.description="<a href=http://${furl}${result}>jump</a>" } } } stage('deploy production'){ when{ environment name: 'DEPLOY_TO', value: 'prod' } steps{ sh ''' sh /opt/scripts/###.sh ${sub_app_name} ${appdir} ### ${WORKSPACE}/${localAppRoot} ### ''' } } stage('deploy pre-release'){ when{ environment name: 'DEPLOY_TO', value: 'staging' } steps{ sh ''' echo "hello" sh /opt/scripts/###.sh ${sub_app_name} ${appdir} ### ${WORKSPACE}/${localAppRoot} ### $stagingip ''' } } } }
如图: