Jenkins is treating the dir
step weirdly in docker agents.
#!groovy
pipeline {
agent none
stages {
stage('test not in docker') { //everything in here works fine
agent any
steps {
dir('../there') {
sh 'touch there'
}
sh 'ls ../there'
dir('../some-repo') {
git credentialsId: 'jenkins-github_ssh',
url: '[email protected]:user/some-repo.git',
branch: 'master'
}
sh 'ls ../some-repo'
}
}
stage('test in docker') {
agent {
docker { image 'debian:stable' }
}
steps {
dir('here') {
sh 'touch here'
}
sh 'ls here' // this works
dir('../there') { //not sure where this dir lives
sh 'touch there' // this hangs
}
sh 'ls ../there'
dir('../some-repo') { //this dir is on the host not in the container
git credentialsId: 'jenkins-github_ssh',
url: '[email protected]:user/some-repo.git',
branch: 'master'
}
sh 'ls ../some-repo' // ls: cannot access '../some-repo': No such file or directory
}
}
}
}
The first stage clones a repo at the peer level of the working directory, and it works fine.
The second stage demonstrates that in a docker agent:
- you can create subdirectories and do stuff with them in a docker agent
- Launching a shell in a directory outside the working directory hangs
- cloning a repo into a dir outside the current working directory doesn't hang or crash, but it ends up on the host and not in the container.
To run the third thing in the docker agent I do have to comment out the dir('../there'){sh 'touch there'}
that hangs
Logs from the sh hang (org.jenkinsci.plugins.durabletask.BourneShellScript.LAUNCH_DIAGNOSTICS
is true according to $jenkinsURL/systemInfo):
[Pipeline] dir
Running in /tmp/jenkins-workdir/workspace/there
[Pipeline] {
[Pipeline] sh
process apparently never started in /tmp/jenkins-workdir/workspace/there@tmp/durable-21cae374
(running Jenkins temporarily with -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.LAUNCH_DIAGNOSTICS=true might make the problem clearer)
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
I feel like I'm completely missing a section of the jenkins documentation titled something like "limitations of docker agents", but I'm not able to find anything on this because "jenkinsfile docker dir" or "jenkinsfile docker clone repo" are too generic of search terms.
My actual goal is to get a second repo the repo I'm building depends on into a docker container, so I'm going to just try passing credentials into the container to run git clone inside the container.
I would like suggestions on where to find documentation on this, or help understanding what is happening so I can suggest documentation to be created.
question from:
https://stackoverflow.com/questions/65853029/jenkinsfile-dir-step-acting-different-in-docker-agent-from-non-docker-agents 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…