jenkins - 如何使用 Jenkins Pipeline Groovy 脚本检索当前工作区?

标签 jenkins groovy jenkins-pipeline

我正在尝试使用 Groovy 管道脚本获取 Jenkins 构建的当前工作区:

node('master') {
    // PULL IN ENVIRONMENT VARIABLES
    // Jenkins makes these variables available for each job it runs
    def buildNumber = env.BUILD_NUMBER
    def workspace = env.WORKSPACE
    def buildUrl = env.BUILD_URL

    // PRINT ENVIRONMENT TO JOB
    echo "workspace directory is ${workspace}"
    echo "build URL is ${env.BUILD_URL}"
}

它返回:

[Pipeline] Allocate node : Start
Running on master in /Users/Shared/Jenkins/Home/jobs/test/workspace
[Pipeline] node {
[Pipeline] echo
workspace directory is null
[Pipeline] echo
build URL is http://localhost:8080/job/test/5/
[Pipeline] } //node
[Pipeline] Allocate node : End
[Pipeline] End of Pipeline
Finished: SUCCESS

最佳答案

对我来说,只需 ${WORKSPACE} 就可以工作,甚至无需初始化变量 workspace

关于jenkins - 如何使用 Jenkins Pipeline Groovy 脚本检索当前工作区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37846028/

相关文章:

jenkins - Cypress 和 Jenkins : Install system dependency "xvfb" via Jenkinsfile

jenkins - 在 Jenkins 2 管道中执行 SonarQube 扫描仪

xml - 如果 Switch 语句中不存在 xml 节点,如何通过断言使 groovy 脚本失败

jenkins - Jenkins-Groovy脚本返回了退出代码126

jenkins - 如何使用 GitHub Org 插件从 jenkins 管道 (jenkinsfile) 触发另一个作业?

csv - Jenkins 管道,解析 csv

Groovy 函数调用省略括号

groovy - String 与 GString 性能

Jenkins 管道 : Shouldn't closures resolve variables the same inside parallel as outside?

jenkins - 将文件从 Jenkins master 复制到 Pipeline 中的 slave