[英]Jenkins: automatically rebase master on test then push if test succesful with jenkins pipeline
對於我的 ETL 腳本,我使用的是持續開發基礎架構:如果測試工作流成功,則意味着可以將其推送到生產環境中,然后在夜間運行,如果測試不成功,則不會推送更改,但生產腳本仍在運行。
到目前為止,每次成功更改時,我都會手動將我的測試分支重新定位到我的主分支。 我想自動化這個,一旦測試管道作業完成並成功,Jenkins 會自動在測試分支上重新設置主分支並將其推送到遠程存儲庫。
這是我當前的 jenkins 管道代碼模型(Jenkinsfile_test):
def gv
pipeline {
agent any
stages{
stage("init") {
steps {
script {
gv = load "script.groovy"
}
}
}
stage("01_test1") {
when {
changeset "**/01_test1/**"
}
steps {
script {
gv.test1()
}
}
}
stage("02_test2") {
when {
changeset "**/02_test2/**"
}
steps {
script {
gv.test2()
}
}
}
}
post {
success {
echo "success"
withCredentials([usernamePassword(credentialsId: 'xxx',
usernameVariable: 'xxx',
passwordVariable: 'xxx')]){
sh "git checkout master"
sh "git rebase test"
sh("git push http://$username:$password@http://git-server/test.git test")
}
}
}
}
我嘗試了在這里找到的解決方案: Is it possible to Git merge / push using Jenkins pipeline
但它不起作用。 我實際上不知道如何設置我的成功步驟。
以下是我在運行 jenkins 管道作業時遇到的錯誤:
Error when executing success post condition:
java.io.IOException: CreateProcess error=2, The system cannot find the file specified
Caused: java.io.IOException: Cannot run program "nohup" (in directory "C:\Program Files
(x86)\Jenkins\workspace\test_pipeline")
任何幫助將非常感激。
“'nohup' not found 錯誤”的主要原因看起來像是 Windows 不支持sh
步驟。 例如,您可以使用bat
或安裝Cygwin
。 看到這個答案。
使用bat
應該可以像這樣工作:
post {
success {
echo "success"
withCredentials([usernamePassword(credentialsId: 'xxx',
usernameVariable: 'xxx',
passwordVariable: 'xxx')]){
bat "git checkout master"
bat "git rebase test"
bat("git push http://$username:$password@http://git-server/test.git test")
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.