Jenkins:如果使用 Jenkins 管道测试成功,则在测试时自动重新设置 master 然后推送
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")
}
}
}
}
我尝试了在此处找到的解决方案:
但它不起作用。我其实不知道如何设置我的成功步骤。
这是我在 运行 执行 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' 未找到错误”的主要原因似乎是 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")
}
}
}
对于我的 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")
}
}
}
}
我尝试了在此处找到的解决方案:
但它不起作用。我其实不知道如何设置我的成功步骤。
这是我在 运行 执行 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' 未找到错误”的主要原因似乎是 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")
}
}
}