如何在詹金斯用于Windows批处理命令的环境变量? [英] How are environment variables used in Jenkins with Windows Batch Command?

查看:93
本文介绍了如何在詹金斯用于Windows批处理命令的环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用詹金斯(全球)环境变量在我的XCOPY脚本。

  $ {}工作空间不起作用
$ {WORKSPACE}不工作
$ {WORKSPACE}'不工作


解决方案

我一无所知詹金斯,但它看起来像你试图访问使用某种形式的UNIX语法的环境变量 - 这是行不通的。

如果变量的名称是工作区时,则该值在Windows批处理使用
扩大
%WORKSPACE%。扩大这种形式在分析时进行。例如,这将打印到屏幕工作区的值

 回声%WORKSPACE%

如果您在执行时所需要的值,那么你需要使用延迟扩展!WORKSPACE!。延迟扩张通常不被默认启用。使用 SETLOCAL EnableDelayedExpansion 来启用它。往往需要延迟扩展,因为括号中的code块被解析的一次,所以块内赋值以后不能在同一区块内,除非你使用延迟扩展阅读。

  SETLOCAL enableDelayedExpansion
集WORKSPACE =前

  集WORKSPACE = AFTER
  回声正常扩展=%WORKSPACE%
  回声延迟扩展=!工作区!

的上述输出是

 普通扩展=前
延迟扩展= AFTER

使用 HELP SET SET /?通过命令行来获得有关Windows环境变量和详细信息各种扩展选项。例如,它解释了如何做搜索/替换和子业务。

I'm trying to use Jenkins (Global) environment variables in my xcopy script.

${WORKSPACE} doesn't work
"${WORKSPACE}" doesn't work
'${WORKSPACE}' doesn't work

解决方案

I know nothing about Jenkins, but it looks like you are trying to access environment variables using some form of unix syntax - that won't work.

If the name of the variable is WORKSPACE, then the value is expanded in Windows batch using
%WORKSPACE%. That form of expansion is performed at parse time. For example, this will print to screen the value of WORKSPACE

echo %WORKSPACE%

If you need the value at execution time, then you need to use delayed expansion !WORKSPACE!. Delayed expansion is not normally enabled by default. Use SETLOCAL EnableDelayedExpansion to enable it. Delayed expansion is often needed because blocks of code within parentheses are parsed all at once, so a value assigned within the block cannot be read later within the same block unless you use delayed expansion.

setlocal enableDelayedExpansion
set WORKSPACE=BEFORE
(
  set WORKSPACE=AFTER
  echo Normal Expansion = %WORKSPACE%
  echo Delayed Expansion = !WORKSPACE!
)

The output of the above is

Normal Expansion = BEFORE
Delayed Expansion = AFTER

Use HELP SET or SET /? from the command line to get more information about Windows environment variables and the various expansion options. For example, it explains how to do search/replace and substring operations.

这篇关于如何在詹金斯用于Windows批处理命令的环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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