1. 程式人生 > >Jenkins Pipeline

Jenkins Pipeline

可以在pipeline工程中開啟Pipeline Syntax

pipeline {
    agent any
    stages {
        stage('ready') {
              steps {
                    sh 'echo "ready to build"'
              }
        }
        stage('Build') {
              steps {
                    echo "Building"
                    sh '''mvn clean install'''
              }
        }
        stage('Test') {
              steps {
                   echo "Testing"
              }
        }
        stage('Deploy') {
              steps {
                   echo "Deploying"'
                   archiveArtifacts artifacts: '**/target/*. jar', fingerprint: true, onlyIfSuccessful: true
                   sh '''cp ${WORKSPACE}/${buildPath}/target/*. jar ${uploadPath}
              }
        }
    }
}

sh命令多行時需要三個單引號'

常用Step

echo, 列印訊息。echo 'hello' build, 構建其他jenkins jobbuild 'api-job' archiveArtifacts artifacts, 歸檔打包好的檔案archiveArtifacts artifacts: '**/target/*. jar' fileExists, 判斷檔案是否存在。fileExists 'hello'

常用的環境變數

${WORKSPACE} #構建工作區
${GIT_COMMIT} #git程式碼構建時commit SHA1值
${JOB_NAME} #構建…工程名稱