jenkins 修改 并提交代碼

在使用 jenkins 過程中, 有時候需要使用命令修改 代碼,或者配置文件,并提交
典型的應(yīng)用為 把策劃方案 excel 轉(zhuǎn)換為json 文件 供程序來使用.
下面我實(shí)現(xiàn)了一種

pipeline {
    
    agent {
      label 'mac170'
    }
    
    stages {
        
        stage('Git clone repo') {
            steps {
                //cleanWs()
                git credentialsId: 'xxxx-xxxx-xxxx-xxxx-xxxx', url: 'http://xxxx/xxxx.git'
                sh '''
                
                tempBranch=${branch}
                IFS='/'
                read -ra strarr <<< "${tempBranch}"
                IFS=''

                #git branch --delete --force ${strarr[1]}
                git checkout --track -B ${strarr[1]} ${branch}
                git clean -df
                #git checkout --force ${strarr[1]}
                git switch ${strarr[1]}
                git reset --hard ${branch}
                #git pull origin ${strarr[1]}:${strarr[1]}
                
                printenv
                '''
            }
        }

        stage('Change code stage'){
            steps {
                sh '''
        tempBranch=${branch}
        IFS='/'
        read -ra strarr <<< "${tempBranch}"
        IFS=''
                
        echo "導(dǎo)出config"
        #balabala  做事情,或者調(diào)用其他腳本做事情
        
        git add xxxxx.json
        git add xxxxx.json

        #獲取修改的文件數(shù)量
        lineCnt=`git status -s | wc -l`
        lineCnt=`eval echo $lineCnt`
        if [[ $lineCnt != 0 ]] ; then
            echo "有$lineCnt個文件需要提交" 
            git commit -m "update by jenkins"
            git push origin ${strarr[1]}
        else
            echo "沒有任何更新,不需要提交!"
        fi
                '''
            }
        }
    }

}

其中 branch 變量為git paramter 插件的選擇結(jié)果

git paramter 插件
git paramter 設(shè)置
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容