Consider the following pipeline:
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'
}
}
}
}
This build job fails because the %path_workspace_root% does not expand and I get an error that the file I'm looking for cannot be found.
I have tried declaring the strings with double quotes:
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'
}
}
}
}
I have also tried using double quotes and delayed expansion syntax:
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'
}
}
}
}
Variable expansion using the %% syntax is ONLY for use in the BAT '' command. The standard jenkins syntax ${} is what I needed:
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'
}
}
}
}