1. 程式人生 > 其它 >jenkins 獲取當前上傳的分支的commit + url跳轉

jenkins 獲取當前上傳的分支的commit + url跳轉

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 ''' } } } }