我希望能够在Jenkins管道中更改Windows上的环境变量,并且只在该管道中,我该怎么做?
环境变量在系统中设置为:
XXX_DEV_DATA_DIR = E:\tools\jenkins\workspace\data\XXX-IDM
XXX_DEV_LIBS_DIR = E:\tools\jenkins\workspace\dev\libs
我尝试了withEnv命令,但它没有效果:
node
{
withEnv(["XXX_DEV_LIBS_DIR=E:\\tools\\jenkins\\workspace\\dev\\libs', 'XXX_DEV_DATA_DIR=E:\\tools\\jenkins\\workspace\\data\\XXX-IDM-Testing"])
{
dir('E:\\tools\\jenkins\\workspace\\samples\\GetXXXSettings\\bin\\x64\\Release')
{
bat 'GetXXXSettings.exe'
}
}
}
GetXXXSettings.exe应用程序:
class Program
{
static void Main(string[] args)
{
var data = Environment.GetEnvironmentVariable("XXX_DEV_DATA_DIR");
var libs = Environment.GetEnvironmentVariable("XXX_DEV_LIBS_DIR");
Console.WriteLine("XXX ENVIRONMENT VARIABLES");
Console.WriteLine();
Console.WriteLine($"XXX_DEV_DATA_DIR = {data}");
Console.WriteLine($"XXX_DEV_LIBS_DIR = {libs}");
Console.WriteLine();
Console.WriteLine("END");
}
}
结果如下:
XXX ENVIRONMENT VARIABLES
XXX_DEV_DATA_DIR = E:\tools\jenkins\workspace\data\XXX-IDM
XXX_DEV_LIBS_DIR = E:\tools\jenkins\workspace\dev\libs', 'XXX_DEV_DATA_DIR=E:\tools\jenkins\workspace\data\XXX-IDM-Testing
END
环境变量XXX_DEV_DATA_DIR未更改,我不确定XXX_DEV_LIBS_DIR发生了什么。
答案 0 :(得分:1)
看起来你在withEnv上发出引号,尝试更新它
node
{
withEnv(['XXX_DEV_LIBS_DIR=E:\\tools\\jenkins\\workspace\\dev\\libs', 'XXX_DEV_DATA_DIR=E:\\tools\\jenkins\\workspace\\data\\XXX-IDM-Testing'])
{
dir('E:\\tools\\jenkins\\workspace\\samples\\GetXXXSettings\\bin\\x64\\Release')
{
bat 'GetXXXSettings.exe'
}
}
}