I have windows 10 and I want to execute the sh command in the Jenkinsfile from Jenkins pipeline using bash for Ubuntu for windows, but it doesn\'t work
I have the fo
So you want the job running under WSL. If you want all jobs running under WSL have you considered installing Jenkins under WSL? Then everything is already in GNU land and you don't have to bridge the envrionment/culture of windows to GNU from within your Jenkins configuration.
With Git for Windows, I had to add C:\Program Files\Git\bin
to the PATH
environment variable of the slave node in Jenkins (to get access to sh
), then add C:\Program Files\Git\usr\bin
to the PATH
locally on the Windows slave too (to get access to nohup
).
My observation is that the agent seems to be trying to run nohup in the context where the agent.jar is run, not in the container. It didn't matter what I put in the container, the error message was the same. By putting nohup and sh in the PATH where the jenkins agent is running, I see a change in behavior.
git config core.sparsecheckout # timeout=10 git checkout -f c64c7bf905b6a4f5a8f85eb23bbd108f4c805386 sh: /home/jenkins/workspace/projname/simple_docker@tmp/durable-9fedc317/jenkins-log.txt: No such file or directory sh: /home/jenkins/workspace/projname/simple_docker@tmp/durable-9fedc317/jenkins-result.txt.tmp: No such file or directory mv: cannot stat '/home/jenkins/workspace/projname/simple_docker@tmp/durable-9fedc317/jenkins-result.txt.tmp': No such file or directory
I am seeing a folder /home/jenkins/workspace/projname/simple_docker@tmp/durable-9fedc317 which contains a file "script.sh" with the contents "docker inspect -f . repositoryname:tagname"
When this docker command is run manually on the command line, it always produces a single line of output consisting of a single period character. I have no doubt this is not what the jenkins system is looking for.
Windows doesn't understand the "sh" command. To enable this, add
C:\Program Files\Git\bin &
C:\Program Files\Git\usr\bin
to the System Environment variable PATH, than restart your system.
Than execute your command in jenkins, it will work.
From a very quick search, it looks like your error is related to the following issue : JENKINS-33708
The main cause looks like the sh
step is not supported on the Windows. You may use bat
or install Cygwin
for instance.
Nevertheless two solutions were proposed in the previous link, suggesting you to do the following steps :
C:\Program Files\Git\bin
) is in the global search path, in order for Jenkins to find sh.exeDepending on your installation you may have to use these paths :
Switching sh to bat worked for me - I am running Jenkins on Windows. But only after I had resolved an issue caused by the fact I had not configured my tools (maven and the JDK) correctly in Jenkins either.