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

问题描述

  node('master')使用一个Groovy管道脚本来获取我的Jenkins Build的当前工作空间。 ){
//拉到环境变量
// Jenkins使这些变量可用于它运行的每个作业
def buildNumber = env.BUILD_NUMBER
def workspace = env.WORKSPACE
def buildUrl = env.BUILD_URL
//打印环境以工作
echoworkspace directory is $ {workspace}
echobuild URL is $ {env.BUILD_URL}

返回

<$ p $在$ master / in / Users / Shared / Jenkins / Home / jobs / test / workspace中运行
[Pipeline] node {
[管道] echo
工作空间目录为空
[管道] echo
构建URL为http:// localhost:8080 / job / test / 5 /
[Pipeline]} / /节点
[管道]分配节点:结束
[管道]管道结束
完成:SUCCESS


解决方案

对于我而言,$ {workspace}工作时甚至没有初始化变量workspace。


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}"
}

It returns

   [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
解决方案

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

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

09-01 22:12