如何使用 Jenkins Pipeline Groovy 脚本检索当前工作区? [英] How to retrieve current workspace using Jenkins Pipeline Groovy script?

查看:28
本文介绍了如何使用 Jenkins Pipeline Groovy 脚本检索当前工作区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to get the current workspace of my Jenkins build using a Groovy pipeline script:

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 就可以工作.

For me just ${WORKSPACE} worked without even initializing the variable workspace.

这篇关于如何使用 Jenkins Pipeline Groovy 脚本检索当前工作区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆