我有下面的代码,对我不起作用。
dir('anyName'){
checkout scm: [$class: 'GitSCM', branches: [[name: PIPELINE_VERSION]],
userRemoteConfigs: [[credentialsId: 'some-id', url: 'some git repo']]
]
}
def some = load "./pipelines/environment/some.groovy"但我得到了以下错误。如何加载文件并在以后使用其内部功能。
/mnt/data/jenkins/workspace//pipelines/environment/some.groovy :java.nio.file.NoSuchFileException
发布于 2021-08-04 20:54:42
来自目录步骤文档:
更改当前目录。dir块中的任何步骤都将使用此目录作为当前目录,而任何相对路径都将使用它作为基本路径。
dir命令只为在dir {}块内执行的代码更改基本目录,因此,当您在dir块之后加载文件时,您将返回到原始工作区,而找不到该文件。
要解决这个问题,可以使用完整的路径加载文件:
dir('anyName'){
checkout scm: [$class: 'GitSCM', branches: [[name: PIPELINE_VERSION]],
userRemoteConfigs: [[credentialsId: 'some-id', url: 'some git repo']]
]
}
// From here we are back to the default workspace
def some = load "./anyName/pipelines/environment/some.groovy"或者将文件加载到dir块中:
dir('anyName'){
checkout scm: [$class: 'GitSCM', branches: [[name: PIPELINE_VERSION]],
userRemoteConfigs: [[credentialsId: 'some-id', url: 'some git repo']]
]
def some = load "./pipelines/environment/some.groovy"
}https://stackoverflow.com/questions/68656862
复制相似问题