pipeline流水线语法格式
def call() { pipeline { agent any options { buildDiscarder logRotator(daysToKeepStr: '5', numToKeepStr: '5') gitLabConnection 'gitlab-10.60.30.180' sidebarLinks([ [displayName: 'workspace', iconFileName: 'folder.png', urlName: "http://10.88.44.64:8080/view/pipeline/job/$JOB_NAME/$BUILD_ID/execution/node/4/ws/"] ]) } tools { jdk 'jdk 8' nodejs 'node10.15' } stages { stage("拉代码"){ steps{ sh ''' echo $appconfig ''' script { SUB_GROUP = sh (script:"echo $JOB_NAME |awk -F'+' '{print \$(NF-1)}'", returnStdout: true).trim() PROJ_NAME_frontend = sh (script:"echo $JOB_NAME |awk -F'+' '{print \$NF}'", returnStdout: true).trim() URL_GIT_frontend = sh (script:"echo http://10.63.34.190/dzrj_project/${SUB_GROUP}/${PROJ_NAME_frontend}.git", returnStdout: true).trim() } checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '4f71b5cd-9430-492d-8112-b008ae2776ab', url: "${URL_GIT_frontend}"]]]) } } stage("sonar检查"){ steps{ script { PROJ_ID = sh (script:"echo $JOB_NAME |awk -F'-' '{print \$1}'", returnStdout: true).trim() SONAR_KEY = sh (script:"echo ${PROJ_ID}-${SUB_GROUP}", returnStdout: true).trim() } withSonarQubeEnv('10.153.61.80') { // some block sh "SonarScanner -Dsonar.host.url=http://10.153.61.80:9000 -Dsonar.sourceEncoding=UTF-8 -Dsonar.sources=src/ -Dsonar.login=63429399c559fd273dea3ce3e515e09cad9f8bbb -Dsonar.projectVersion=v1.0 -Dsonar.java.binaries=/ -Dsonar.projectKey=${SONAR_KEY} -Dsonar.java.source=1.8 -Dsonar.projectName=${JOB_NAME} -Dsonar.projectBaseDir=/var/lib/jenkins/workspace/${JOB_NAME}" } } } stage('质量门限') { steps { sleep(20) timeout(time: 1, unit: 'MINUTES') { waitForQualityGate abortPipeline: true } } } stage("前端打包"){ steps{ script{ env.imageTag = sh (script: 'git rev-parse --short HEAD ${GIT_COMMIT}', returnStdout: true).trim() } sh "echo $env.imageTag" sh ''' echo $PATH node -v npm -v cd ${WORKSPACE} if [ -e node_modules/.bin/vue-cli-service ] then chmod 777 node_modules/.bin/vue-cli-service else echo "未上传node_modules或前端框架为老版本" fi echo $appconfig npm cache clean -f node deploy $appconfig ''' } } } } }
def call() { pipeline { agent any options { buildDiscarder logRotator(daysToKeepStr: '5', numToKeepStr: '5') gitLabConnection 'gitlab' sidebarLinks([ [displayName: 'workspace', iconFileName: 'folder.png', urlName: "http://10.88.44.64:8080/view/pipeline/job/$JOB_NAME/$BUILD_ID/execution/node/4/ws/"] ]) } tools { jdk 'jdk 8' nodejs 'node10.15' } triggers { pollSCM ignorePostCommitHooks: true, scmpoll_spec: '*/1 * * * *' } stages { stage("拉代码"){ steps{ script { SUB_GROUP = sh (script:"echo $JOB_NAME |awk -F'+' '{print \$(NF-2)}'", returnStdout: true).trim() PROJ_NAME_backend = sh (script:"echo $JOB_NAME |awk -F'+' '{print \$(NF-1)}'", returnStdout: true).trim() PROJ_NAME_frontend = sh (script:"echo $JOB_NAME |awk -F'+' '{print \$NF}'", returnStdout: true).trim() URL_GIT_backend = sh (script:"echo http://10.63.34.190/dzrj_project/${SUB_GROUP}/${PROJ_NAME_backend}.git", returnStdout: true).trim() URL_GIT_frontend = sh (script:"echo http://10.63.34.190/dzrj_project/${SUB_GROUP}/${PROJ_NAME_frontend}.git", returnStdout: true).trim() } checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'front']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '4f71b5cd-9430-492d-8112-b008ae2776ab', url: "${URL_GIT_frontend}"]]]) checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'backend']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '4f71b5cd-9430-492d-8112-b008ae2776ab', url: "${URL_GIT_backend}"]]]) } } stage("sonar检查"){ steps{ script { PROJ_ID = sh (script:"echo $JOB_NAME |awk -F'-' '{print \$1}'", returnStdout: true).trim() SONAR_KEY = sh (script:"echo ${PROJ_ID}-${SUB_GROUP}", returnStdout: true).trim() } withSonarQubeEnv('10.153.61.80') { // some block sh "SonarScanner -Dsonar.host.url=http://10.153.61.80:9000 -Dsonar.sourceEncoding=UTF-8 -Dsonar.sources=backend/src/ -Dsonar.login=63429399c559fd273dea3ce3e515e09cad9f8bbb -Dsonar.projectVersion=v1.0 -Dsonar.java.binaries=/ -Dsonar.projectKey=${SONAR_KEY} -Dsonar.java.source=1.8 -Dsonar.projectName=${JOB_NAME} -Dsonar.projectBaseDir=/var/lib/jenkins/workspace/${JOB_NAME}" } } } stage('质量门限') { steps { sleep(20) timeout(time: 1, unit: 'MINUTES') { waitForQualityGate abortPipeline: true } } } stage("前端打包"){ steps{ script{ env.imageTag = sh (script: 'cd front;git rev-parse --short HEAD ${GIT_COMMIT}', returnStdout: true).trim() } sh "echo $env.imageTag" sh ''' if [ -e front/node_modules/.bin/vue-cli-service ] then chmod 777 front/node_modules/.bin/vue-cli-service else echo "未上传node_modules或前端框架为老版本" fi cd front echo $PWD npm cache clean -f npm rebuild node-sass npm run build echo ${WORKSPACE} echo $PWD rm -rf ${WORKSPACE}/backend/src/main/resources/static cp -R ${WORKSPACE}/front/dist/ ${WORKSPACE}/backend/src/main/resources/static/ mkdir -pv ${WORKSPACE}/backend/src/main/resources/static/$env.imageTag ''' } } stage("后端打包"){ steps{ sh "rm -rf ${WORKSPACE}/backend/build" sh "rm -rf ${WORKSPACE}/backend/*.zip" sh "cd ${workspace}/backend ; gradle-4.0 build" } } stage("重命名jar包"){ steps{ script{ env.imageTag = sh (script: 'cd backend ; git rev-parse --short HEAD ${GIT_COMMIT}', returnStdout: true).trim() } sh "echo $imageTag" sh "printenv" sh "echo ${WORKSPACE}" sh ''' mv ${WORKSPACE}/backend/build/libs/*.jar ${WORKSPACE}/backend/build/libs/`basename ${WORKSPACE}/backend/build/libs/*.jar .jar`-$imageTag.jar ''' } } stage("gradle_publishProjoectPkg"){ steps{ sh "cd ${workspace}/backend ; gradle-4.0 publishProjoectPkg" } } stage("重命名dist.zip"){ steps{ script{ env.imageTag = sh (script: 'cd backend ; git rev-parse --short HEAD ${GIT_COMMIT}', returnStdout: true).trim() } sh "echo $imageTag" sh ''' mv ${WORKSPACE}/backend/dist.zip ${WORKSPACE}/backend/$imageTag.zip ''' } } } } }
def call() { pipeline { agent any options { buildDiscarder logRotator(daysToKeepStr: '5', numToKeepStr: '5') gitLabConnection 'gitlab' sidebarLinks([ [displayName: 'workspace', iconFileName: 'folder.png', urlName: "http://10.88.44.64:8080/view/pipeline/job/$JOB_NAME/$BUILD_ID/execution/node/4/ws/"] ]) } tools { jdk 'jdk 8' } triggers { pollSCM ignorePostCommitHooks: true, scmpoll_spec: '*/1 * * * *' } stages { stage("拉代码"){ steps{ script { SUB_GROUP = sh (script:"echo $JOB_NAME |awk -F'+' '{print \$(NF-1)}'", returnStdout: true).trim() PROJ_NAME = sh (script:"echo $JOB_NAME |awk -F'+' '{print \$NF}'", returnStdout: true).trim() URL_GIT = sh (script:"echo http://10.63.34.190/dzrj_project/${SUB_GROUP}/${PROJ_NAME}.git", returnStdout: true).trim() } checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '4f71b5cd-9430-492d-8112-b008ae2776ab', url: "${URL_GIT}"]]]) //triggers { // pollSCM ignorePostCommitHooks: true, scmpoll_spec: '*/1 * * * *' //} } } stage("sonar检查"){ steps{ script { PROJ_ID = sh (script:"echo $JOB_NAME |awk -F'-' '{print \$1}'", returnStdout: true).trim() SONAR_KEY = sh (script:"echo ${PROJ_ID}-${SUB_GROUP}", returnStdout: true).trim() } withSonarQubeEnv('10.153.61.80') { // some block sh "SonarScanner -Dsonar.host.url=http://10.153.61.80:9000 -Dsonar.sourceEncoding=UTF-8 -Dsonar.sources=src/ -Dsonar.login=63429399c559fd273dea3ce3e515e09cad9f8bbb -Dsonar.projectVersion=v1.0 -Dsonar.java.binaries=/ -Dsonar.projectKey=${SONAR_KEY} -Dsonar.java.source=1.8 -Dsonar.projectName=${JOB_NAME} -Dsonar.projectBaseDir=/var/lib/jenkins/workspace/${JOB_NAME}" } } } stage('质量门限') { steps { sleep(20) timeout(time: 1, unit: 'MINUTES') { waitForQualityGate abortPipeline: true } } } stage("后端打包"){ steps{ sh "rm -rf ${WORKSPACE}/build" sh "rm -rf ${WORKSPACE}/*.zip" sh "gradle-4.0 build" } } stage("重命名jar包"){ steps{ script{ env.imageTag = sh (script: 'git rev-parse --short HEAD ${GIT_COMMIT}', returnStdout: true).trim() } sh "echo $imageTag" sh "printenv" sh "echo $PWD" sh "mv ${WORKSPACE}/build/libs/*.jar ${WORKSPACE}/build/libs/`basename ${WORKSPACE}/build/libs/*.jar .jar`-${imageTag}.jar" } } stage("gradle_zipProjectPkg"){ steps{ sh "gradle-4.0 zipProjectPkg" } } stage("重命名dist.zip"){ steps{ script{ env.imageTag = sh (script: 'git rev-parse --short HEAD ${GIT_COMMIT}', returnStdout: true).trim() } sh "echo $imageTag" sh "mv ${WORKSPACE}/dist.zip ${WORKSPACE}/${imageTag}.zip" } } } } }