@Library('siheng-devops') _ pipeline { agent { label 'jnlp-slave'} options { timeout(time: 200, unit: 'MINUTES') gitLabConnection('gitlab') } environment { PROJECT = "$NAME" IMAGE_REPO = "harbor.service-k8s-test.oigbuy.com/spring-cloud/$NAME" IMAGE_CREDENTIAL = "login-Harbor" DINGTALK_CREDS = credentials('dingTalk') GITURL = "$GIT" #"$GIT为jenkins传递参数" GITBRANCH = "$BRANCH" DVERSION = "$VERSION" CODETYPE = "$TYPE" DSTAGE = "$STAGE" DENV = "$ENV" FLYWAYIP = "$FLYWAYIP" FLYWAYPORT = "$FLYWAYPORT" FLYWAYDB = "$FLYWAYDB" FLYWAYUSER = "$FLYWAYUSER" FLYWAYPASSWORD = "$FLYWAYPASSWORD" FLYWAYFILE = "$WORKSPACE/$FLYWAYFILE" } stages { stage('checkout') { steps { container('tools') { checkout([$class: 'GitSCM', branches: [[name: "*/$GITBRANCH"]], extensions: [], userRemoteConfigs: [[credentialsId: 'git_jenkins', url: "$GITURL"]]])#"此为拉取项目代码" } } } stage('sonar') { when { anyOf{ environment name: 'STAGE', value: 'sonar' environment name: 'STAGE', value: 'all' } } steps { container('tools') { script { devops.scan().start() } } } } stage('unitest'){ when { anyOf{ environment name: 'STAGE', value: 'unitest' environment name: 'STAGE', value: 'all' } } steps { echo "Unit Test Stage Skip..." } } stage('sql') { when { anyOf{ environment name: 'STAGE', value: 'sql' environment name: 'STAGE', value: 'all' } } steps { container('tools') { script{ sh "flyway -url=jdbc:mysql://$FLYWAYIP:$FLYWAYPORT/$FLYWAYDB?charset=utf8mb4 -user=$FLYWAYUSER -password=$FLYWAYPASSWORD -locations=filesystem:$FLYWAYFILE -baselineOnMigrate=true -cleanDisabled=true migrate" sh "flyway -url=jdbc:mysql://$FLYWAYIP:$FLYWAYPORT/$FLYWAYDB?charset=utf8mb4 -user=$FLYWAYUSER -password=$FLYWAYPASSWORD -locations=filesystem:$FLYWAYFILE -baselineOnMigrate=true -cleanDisabled=true info" } } } } stage('package') { when { anyOf{ environment name: 'STAGE', value: 'package' environment name: 'STAGE', value: 'all' } } steps { container('tools') { sh 'mvn clean package -Dmaven.test.skip=true' script{ devops.docker( "${IMAGE_REPO}", "${VERSION}", IMAGE_CREDENTIAL ).build().push() } } } } stage('deploy') { when { anyOf{ environment name: 'STAGE', value: 'deploy' environment name: 'STAGE', value: 'all' } }#判断传递参数是否执行此段代码 steps { container('tools') { script{ devops.deploy("manifests",true,"manifests/deployment.yaml").start() } } } } } post { success { script{ devops.notificationSuccess(PROJECT,"dingTalk") } } failure { script{ devops.notificationFailed(PROJECT,"dingTalk") } } } }
标签:隔离,项目,value,name,environment,steps,jenkinsfile,true,STAGE From: https://www.cnblogs.com/quemengqio/p/17086691.html