考虑以下管道:
pipeline {
/* continuous build pipeline for jenkins */
agent any
environment {
/* initialize vairables for this job */
path_msbuild = 'C:\\Program Files (x86)\\MSBuild\\14.0\\Bin\\msbuild.exe'
path_workspace_root = 'C:\\Program Files (x86)\\Jenkins\\workspace\\MyApplication'
path_solutionfile = '%path_workspace_root%\\MyApplication.sln' /* this variable doesn't expand */
databasename = 'elements'
}
stages {
stage ('solution') {
steps {
echo 'building solution'
bat '"%path_msbuild%" "%path_solutionfile%" /p:Configuration=Release'
}
}
}
}
此构建作业失败,因为%path_workspace_root%不会扩展,并且我收到一条错误消息,即找不到我要查找的文件。
我尝试用双引号声明字符串:
pipeline {
/* continuous build pipeline for jenkins */
agent any
environment {
/* initialize vairables for this job */
path_msbuild = 'C:\\Program Files (x86)\\MSBuild\\14.0\\Bin\\msbuild.exe'
path_workspace_root = 'C:\\Program Files (x86)\\Jenkins\\workspace\\MyApplication'
path_solutionfile = "%path_workspace_root%\\MyApplication.sln" /* this variable still doesn't expand */
databasename = 'elements'
}
stages {
stage ('solution') {
steps {
echo 'building solution'
bat '"%path_msbuild%" "%path_solutionfile%" /p:Configuration=Release'
}
}
}
}
我也尝试过使用双引号和延迟扩展语法:
pipeline {
/* continuous build pipeline for jenkins */
agent any
environment {
/* initialize vairables for this job */
path_msbuild = 'C:\\Program Files (x86)\\MSBuild\\14.0\\Bin\\msbuild.exe'
path_workspace_root = 'C:\\Program Files (x86)\\Jenkins\\workspace\\MyApplication'
path_solutionfile = "!path_workspace_root!\\MyApplication.sln" /* this variable still doesn't expand */
databasename = 'elements'
}
stages {
stage ('solution') {
steps {
echo 'building solution'
bat '"%path_msbuild%" "%path_solutionfile%" /p:Configuration=Release'
}
}
}
}
答案 0 :(得分:0)
使用%%语法的变量扩展仅可用于BAT''命令。标准的詹金斯语法$ {}是我所需要的:
pipeline {
/* continuous build pipeline for jenkins */
agent any
environment {
/* initialize vairables for this job */
path_msbuild = 'C:\\Program Files (x86)\\MSBuild\\14.0\\Bin\\msbuild.exe'
path_workspace_root = 'C:\\Program Files (x86)\\Jenkins\\workspace\\MyApplication'
path_solutionfile = '${path_workspace_root}\\MyApplication.sln' /* this variable doesn't expand */
databasename = 'elements'
}
stages {
stage ('solution') {
steps {
echo 'building solution'
bat '"%path_msbuild%" "%path_solutionfile%" /p:Configuration=Release'
}
}
}
}