0

I am creating a simple pipeline for terraform as below in jenkins[installed on windows] seems sh command is not working, i have git bash in my system [i.e.: C:\Program Files\Git\bin)]in my system and have provided path in environment variables, still getting an error as below:

java.io.IOException: CreateProcess error=2, The system cannot find the file specified

Caused: java.io.IOException: Cannot run program "nohup" (in directory "C:\Users\XYZ.jenkins\workspace\Pipe_Groovy"): CreateProcess error=2, The system cannot find the file specified

Code for reference:

pipeline {
    agent {
        node {
            label 'master'
        }
    }

    stages {

        stage('terraform started') {
            steps {
                sh 'echo "Started...!" '
            }
        }
        stage('git clone') {
            steps {
                sh 'sudo rm -r *;sudo git clone https://gist.github.com/XXXXX/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
            }
        }
        stage('tfsvars create'){
            steps {
                sh 'sudo cp /home/ec2-user/vars.tf ./jenkins/'
            }
        }

Please advice.

2 Answers 2

3

You should be using bat instead of sh in Jenkins pipelines on Windows. Here is the documentation on using bat:

https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#-bat-%20windows%20batch%20script

Even then, you probably won't need nohup. But, if you do still need nohup, consider installing Cygwin.

See https://issues.jenkins-ci.org/browse/JENKINS-33708 for a related Jenkins JIRA issue.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks , I will check this
1

With Git for Windows Version 2.16.2, I was able to add C:\Program Files\Git\usr\bin to the PATH (rather than C:\Program Files\Git\bin) and consequently my sh commands work in both FreeStyle and Pipeline builds.

No mklink was necessary.

1 Comment

Thanks, the mklink caused me weird behavior like adding path to one of my env properties

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.