bsky
bsky

Reputation: 20222

nohup: failed to run command `sh`: No such file or directory

I have the following pipeline script in Jenkins:

node {

  withMaven(globalMavenSettingsFilePath: '/my/path/apache-maven-3.2.2/conf/settings.xml', jdk: 'JDK 1.8.0u92', maven: 'apache-maven-3.2.2', mavenSettingsFilePath: '/my/path/apache-maven-3.2.2/conf/settings.xml') {

    sh '/my/path/apache-maven-3.2.2/bin/mvn clean install'
  }
}

For this, I am getting:

nohup: failed to run command `sh`: No such file or directory
ERROR: script returned exit code -2

Why is this?

I am sure that the path to my Maven installation is correct. When I run a job without the pipeline, Maven builds with no errors and I can see that it uses the same path.

Upvotes: 1

Views: 16554

Answers (4)

Rashmi Aglawe
Rashmi Aglawe

Reputation: 23

This error comes when you are trying to run script copied from windows machine to unix machine. YOU need to change the format to unix using : dos2unix <scriptname.sh> and the run your script in unix ./<scriptname.sh>

Upvotes: 1

Majki
Majki

Reputation: 618

This might be the result of modifying PATH.

Check your script and Global Properties and remove modifications to PATH. It is now recommended to use PATH+extra instead. It would still be picked up, but without breaking actual PATH.

Related issue on Jenkins: https://issues.jenkins-ci.org/browse/JENKINS-41339

Upvotes: 7

bsky
bsky

Reputation: 20222

In the end, I used shell instead of sh and it worked. No idea why, they don't have a proper API.

Upvotes: 3

khmarbaise
khmarbaise

Reputation: 97389

I would suggest to use it like this:

  withMaven(
            maven: 'M3',
            mavenSettingsConfig: 'maven-settings-for-the-task',
            mavenLocalRepo: '.repository') {

        // Run the maven build
        sh "mvn clean install"
    }

Apart from that I would not use absolute paths to global settings.xml nor to user settings.xml. I would prefer using usage of "Config File Provider Plugin" which has the advantage to have the settings.xml on Master and available on all nodes.

See also the documentation: https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Maven+Plugin

Upvotes: 1

Related Questions