zhuguojun6 发表于 2019-2-20 16:22:56

pipeline devops实例代码

本帖最后由 zhuguojun6 于 2019-2-20 16:30 编辑

部署流程:
确认执行>>克隆代码>>获取代码信息>>sonarqube分析代码>>artifactory编译并上传交付物和编译信息>>调用部署任务



node {
//   def server = Artifactory.server "artifactory_135"
//   def server = Artifactory.newServer url: 'artifactory-url', username: 'username', password: 'password'

   def server = Artifactory.newServer url: "http://172.17.195.136:8040/artifactory", credentialsId:'jfrog-artifactory'
   def rtMaven = Artifactory.newMavenBuild()
   def buildInfo
   stage('Confirm') {
      timeout(time: 10, unit: 'SECONDS') {
             input 'Make Sure Start ?'
         }
   }



   stage ('clone') {
       checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '',locations: [], quietOperation: true, workspaceUpdater: [$class: 'CheckoutUpdater']])
   }


   stage('code info') {
//       pom_info = readMavenPom file: 'pom.xml'
//       env.IMAGE = pom_info.getArtifactId()
//       env.VERSION = pom_info.getVersion()
         env.GROUPID = readMavenPom().getGroupId()
         env.IMAGE = readMavenPom().getArtifactId()
         env.VERSION = readMavenPom().getVersion()
         echo "GROUPID:${GROUPID}"
         echo "IMAGE:${IMAGE}"
         echo "VERSION: ${VERSION}"
         currentBuild.description = "IMAGE: ${IMAGE} -- VERSION: ${VERSION}"
    }
   
   stage ('sonarqube') {
       withSonarQubeEnv ('sonarqube'){
         sh '''
         sonar-runner \
         -Dsonar.projectKey=${IMAGE} \
         -Dsonar.projectName=${IMAGE} \
         -Dsonar.projectVersion=${VERSION} \
         -Dsonar.sources=./src/main/ \
         -Dsonar.souceEncoding=utf-8 \
         -Dsonar.language=java \
         -Dsonar.java.binaries=./src/main/
         '''

       }
       sleep 5
       timeout(time: 1) {
          def qg = waitForQualityGate()
          if (qg.status != 'OK') {
            error "Pipeline aborted due to quality gate failure: ${qg.status}"
          }
       }

}




   stage('maven build') {
       rtMaven.tool = 'maven'
       rtMaven.resolver server: server,releaseRepo: 'maven' ,snapshotRepo:'maven-snapshot'
       rtMaven.deployer server: server,releaseRepo: 'generic-local' ,snapshotRepo:'generic-local-snapshot'
       buildInfo = rtMaven.run pom: 'pom.xml',goals: 'clean package -Dmaven.test.skip=true'

   }

   stage('push build') {
         server.publishBuildInfo buildInfo

   }
   stage('deploy war') {
         build job: 'artifactory_deploy' ,parameters:


   }
}




页: [1]
查看完整版本: pipeline devops实例代码