首页 > 解决方案 > Jenkins docker build customWorkspace 不起作用

问题描述

例如,为什么 customWorkspace 不适用于新目录/tmp/checkout-directory

如果我选择/var/jenkins_home/workspace/44. pipeline-agent-dockerfile-customWorkspace/checkout-directory那么它的工作原理。

pipeline {
    agent none
    stages {
        stage('Checkout') {
            agent any
            steps {
                checkout([$class: 'GitSCM',
                        branches: [[name: "origin/master"]],
                        userRemoteConfigs: [[
                            url: 'https://github.com/test/pipeline-agent-dockerfile.git' ]],
                        extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'checkout-directory']]
                    ])
            }
        }
        stage('dockerfile') {
            agent {
                dockerfile {
                    customWorkspace '/tmp/checkout-directory'       
                }
            }
            steps {
                sh 'cat /etc/lsb-release'
            }
        }
    }
}

错误:

Started by user admin
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] stage
[Pipeline] { (Checkout)
[Pipeline] node
Running on Jenkins in /var/jenkins_home/workspace/44. pipeline-agent-dockerfile-customWorkspace
[Pipeline] {
[Pipeline] checkout
The recommended git tool is: NONE
No credentials specified
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://github.com/test/pipeline-agent-dockerfile.git # timeout=10
Fetching upstream changes from https://github.com/test/pipeline-agent-dockerfile.git
 > git --version # timeout=10
 > git --version # 'git version 2.20.1'
 > git fetch --tags --force --progress -- https://github.com/test/pipeline-agent-dockerfile.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
Checking out Revision 49b4a985b835c6bc63ed4d0a548c733c516444a0 (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 49b4a985b835c6bc63ed4d0a548c733c516444a0 # timeout=10
Commit message: "Dockerfile"
 > git rev-list --no-walk 49b4a985b835c6bc63ed4d0a548c733c516444a0 # timeout=10
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (dockerfile)
[Pipeline] node
Running on Jenkins in /var/jenkins_home/workspace/44. pipeline-agent-dockerfile-customWorkspace
[Pipeline] {
[Pipeline] ws
Running in /tmp/checkout-directory
[Pipeline] {
[Pipeline] isUnix
[Pipeline] readFile
[Pipeline] }
[Pipeline] // ws
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
java.nio.file.NoSuchFileException: /tmp/checkout-directory/Dockerfile
    at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
    at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
    at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
    at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)
    at java.nio.file.Files.newByteChannel(Files.java:361)
    at java.nio.file.Files.newByteChannel(Files.java:407)
    at java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:384)
    at java.nio.file.Files.newInputStream(Files.java:152)
    at hudson.FilePath.newInputStreamDenyingSymlinkAsNeeded(FilePath.java:2113)
    at hudson.FilePath.read(FilePath.java:2098)
    at hudson.FilePath.read(FilePath.java:2090)
    at org.jenkinsci.plugins.workflow.steps.ReadFileStep$Execution.run(ReadFileStep.java:104)
    at org.jenkinsci.plugins.workflow.steps.ReadFileStep$Execution.run(ReadFileStep.java:94)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE

标签: jenkins

解决方案


可悲的是,我认为您遇到了一个错误:https ://issues.jenkins.io/browse/JENKINS-48319

似乎已实施修复,但正如您所展示的,它仍然可能不起作用:https ://issues.jenkins.io/browse/JENKINS-53711


推荐阅读