0
votes

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

2 Answers

2
votes

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.

1
votes

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.