0

For my ETL scripts I am using a continuous development infrastructure: if the test workflow is successful, it means that it can be pushed into production and then be run during the night, if the test is not successful then the changes are not pushed but the production scripts still run.

So far I am manually rebasing my test branch to my master branch every time I make a successful change. I would like to automate this so that, once the test pipeline job is complete and successful, Jenkins automatically rebase the master branch on the test branch and push it on the remote repository.

the workflow I wish I had

Here's my current jenkins pipeline code mock-up (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")
            }
        }
    }
}

I tried solutions found here: Is it possible to Git merge / push using Jenkins pipeline

But it is not working. I actually do not know how to set up my success step.

Here are the errors I get when running the jenkins pipeline job:

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")

Any help would be much appreciated.

Jordan Delbar
  • 180
  • 2
  • 9

1 Answers1

1

The main cause for the "'nohup' not found error" looks like the sh step is not supported on Windows. You may use bat or install Cygwin for instance. See this answer.

Using bat should get this working like this:

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")
            }
        }
    }
Lemayian
  • 195
  • 7
  • thanks it was indeed the shell script that was not working: here's what I changed and now it is working: bat "git.exe checkout master" bat "git.exe rebase origin/test" bat "git.exe push http://git-server/test.git master" – Jordan Delbar Dec 01 '21 at 14:16