Jenkins sh script hangs when run in specific container
I've just encountered a similar issue with a custom docker image created by me.It turns out, I was using USER nobody
in Dockerfile of that image and somehow, this way jenkins agent pod was unable to run cat
command or any other shell command from my pipeline script. Running specific container with root user worked for me.
So in your case I would add securityContext: runAsUser: 0 like below.
... - name: argocd image: argoproj/argocd:latest command: - cat tty: true securityContext: runAsUser: 0...
Kubernetes reference: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-container
If the issue is Jenkins related here are some things that may help to solve the problem:
- Issues with the working directory, if you updated Jenkins from some older version the workdir was
/home/jenkins
while in the recent versions it should be/home/jenkins/agent
or if you are running it in Windows the path should start withC:\dir
and not with/dir
- You can try a new clean install with
apt-get --purge remove jenkins
and thenapt-get install jenkins
- This is not your case as you run latest version of durable task plugin. But for other people reference versions prior to 1.28-1.30 caused the same issue.
If your Jenkins is clean the issue should be investigated in a different way, it seems that it's not returning an exit code to the sh command and/or the script is executed in a different shell.I would try to do an sh file to be placed in the working directory of the container
#!/bin/bashecho "testing"echo $?
and try to run it with source my_script.sh
or with bash my_script.sh
$? is the exit code of the latest bash operation, having it printed will make sure that your script is terminated correctly. The source command to run the script will make it run in the same shell that is calling it so the shell variables are accessible. Bash command will run it in another subshell instead.