Cloud Computing Learn Java

Caused: java.io.IOException: Cannot run program “nohup” (in directory “C:\ProgramData\Jenkins”): CreateProcess error=2

This article will explain why we get this error when running Jenkins code. The thing is, “nohup” comes when you run a command not found in windows.

 

This is the code we were using.

pipeline {
    agent any
    environment { 
        
        AWS_DEFAULT_REGION ="us-east-1"
    }

    stages {
        stage('Aws Demo') {
            steps {
                
          withCredentials([[
          $class: 'AmazonWebServicesCredentialsBinding',
          credentialsId: 'jenkins-aws-creds',
          accessKeyVariable: 'AWS_ACCESS_KEY_ID',
          secretKeyVariable:  'AWS_SECRET_ACCESS_KEY']])
          {
         
               
               sh "aws s3 ls"
            
        }
    }
}}} 

 

And we are getting this error when we run a build.

sh-command-not-found

 

We are running this Jenkins on a windows machine, so “sh” is not found in windows. That’s why I am getting this issue,

Started by user Jenkins
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in C:Program
[Pipeline] {
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Aws Demo)
[Pipeline] withCredentials
Masking supported pattern matches of
%AWS_ACCESS_KEY_ID% or
%AWS_SECRET_ACCESS_KEY%
[Pipeline] {
[Pipeline] sh
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.io.IOException: CreateProcess error=2,
The system cannot find the file specified

Caused: java.io.IOException:
Cannot run program "nohup"
(in directory
"C:ProgramDataJenkins.jenkinsworkspaceec2 test"):
CreateProcess error=2,
The system cannot find the file specified
at java.base/java.lang.
ProcessBuilder.start(ProcessBuilder.java:1143)

at WorkflowScript.run(WorkflowScript:20)
at ___cps.transform___(Native Method)

at java.base/java.lang.Thread.run(Thread.java:833)

Finished: FAILURE

 

i-changed-the-code-from-sh-to-bat

 

 

bat-run-successfully