sorry for bad English
i`m trying to use my jenkins BuildNumber in my pipelane, but jenkins dont use it.
My pipe:
node {
stage ('Build')
{
bat '"C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/MSBuild/15.0/Bin/msbuild.exe" D:/rbp-maintenance/_buildscripts/Targets.proj /p:BuildNumber=${env.BUILD_NUMBER} /p:SolutionName=Maintenance.sln'
}
}
In the console i have some text:
D:\rbp-maintenance>"C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/MSBuild/15.0/Bin/msbuild.exe" D:/rbp-maintenance/_buildscripts/Targets.proj /p:BuildNumber=${env.BUILD_NUMBER} /p:SolutionName=Maintenance.sln
Also i`m try to use
env.BUILD_NUMBER
env.$BUILD_NUMBER
What i`m doing wrong?
Use double quotes to enable string interpolation
bat "\"C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/MSBuild/15.0/Bin/msbuild.exe\" D:/rbp-maintenance/_buildscripts/Targets.proj /p:BuildNumber=${env.BUILD_NUMBER} /p:SolutionName=Maintenance.sln"
Related
I am trying to build my .net framework 4.7.2 project (a WCF and WPF application) using jenkins pipeline using docker image (mcr.microsoft.com/dotnet/framework/sdk:4.8-20220215-windowsservercore-ltsc2019) on my machine. This is a POC BTW.
The msbuild command is failing with the below error, I have tried to find solutions over the internet but the solutions I found aren't working for me. :-
"C:\ProgramData\Jenkins\.jenkins\workspace\MyLocalServicePipeline\MyLocalService.sln" (Rebuild target) (1) ->
"C:\ProgramData\Jenkins\.jenkins\workspace\MyLocalServicePipeline\MyWPFApp\MyWPFApp.csproj" (Rebuild target) (8) ->
(CleanupTemporaryTargetAssembly target) ->
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFx.targets(480,10): error MSB3061:
Unable to delete file "obj\x64\Release\MyWPFApp.exe".
Access to the path 'C:\ProgramData\Jenkins\.jenkins\workspace\MyLocalServicePipeline\MyWPFApp\obj\x64\Release\MyWPFApp.exe' is denied.
[C:\ProgramData\Jenkins\.jenkins\workspace\MyLocalServicePipeline\MyWPFApp\MyWPFApp.csproj]
0 Warning(s)
1 Error(s)
jenkins pipeline code is as below :-
pipeline {
agent {
docker
{
image 'mcr.microsoft.com/dotnet/framework/sdk:4.8-20220215-windowsservercore-ltsc2019'
}
}
stages {
stage('Checkout') {
steps {
git url: 'https://lasnab82#bitbucket.org/lasnab82/mylocalservice.git'
}
}
stage('NugetRestore') {
steps {
bat 'nuget restore "%WORKSPACE%\\MyLocalService.sln"'
}
}
stage('Build') {
steps {
bat '"C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\MSBuild\\Current\\Bin\\MSBuild.exe" "%WORKSPACE%\\MyLocalService.sln" /t:"Clean" /p:Configuration=Release /p:Platform="x64"'
bat '"C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\MSBuild\\Current\\Bin\\MSBuild.exe" "%WORKSPACE%\\MyLocalService.sln" /t:"Rebuild" /p:Configuration=Release /p:Platform="x64"'
}
}
}
}
Logically, I think whats going wrong here is that the jenkins docker container agent may not have delete access to delete files which are actually checked out on my machine in jenkins workspace but I dont know how to resolve this access issue on my setup of jenkins.
Appreciate your help.
Thanks!
I have created a pipeline in Jenkins like that:
pipeline {
agent any
stages {
stage('Clean') {
steps {
cleanWs()
}
}
stage('Checkout code') {
steps {
git branch: 'test', credentialsId: <credentialsId>, url: <githubUrl>
}
}
stage('Restore Nuget') {
steps {
bat '"C:\\Nuget\\nuget.exe" restore <ProjectName>.sln'
}
}
stage('Build') {
steps {
bat "\"${tool 'MSBuild'}\" <ProjectName>.sln /p:Configuration=Release;Platform=\"Any CPU\""
}
}
}
}
I have installed MSBuild plugin in Jenkins. In "Global Tool Configuration", I added msbuild path like that: C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild.exe
In the build stage I am getting this error :
MSBUILD : error MSB1009: Project file does not exist.
When I check Jenkins workspace folder, I can see all project files (.sln and .csproj files). What am I doing wrong?
You can try MSBuild path looks like this:
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\amd64\MSBuild.exe
I think MSBuild comes versioned. Can you check if you have the right path?
I have VS2019 as well and my MSBuild path looks like this:
C:\Program Files (x86)\MSBuild\15.0
I have a pipeline which builds a C++ project for that I am using MSBuild, untill now we were using the "Final" configuration parameter, but now I need to switch it to "Release Steam D3D11", when I try to do that I get an error on Jenkins when building the project I guess it is because of the spaces, how can I make Jenkins to take this parameter? this is what I have tried:
stage('Build'){
steps{
script {
def msbuild = tool name: 'MSBuild', type: 'hudson.plugins.msbuild.MsBuildInstallation'
bat "\"${msbuild}\" AoC/Source/project-GRDK.sln /t:Rebuild /p:configuration=Release Steam D3D11"
}
}
}
I have also tried adding ' ' to the configuration name such as :
bat "\"${msbuild}\" AoC/Source/project-GRDK.sln /t:Rebuild /p:configuration='Release Steam D3D11'"
but it does not work neither as I get this error:
00:00:01.407 MSBUILD : error MSB1008: Only one project can be specified.
I sorted it out in case somebody have the same issue, wrapping the string with spaces within \" \" does the job
bat "\"${msbuild}\" AoC/Source/age2-GRDK.sln /t:Rebuild /p:configuration=\"Release Steam D3D11\""
I have a simple declarative pipeline as follows:
pipeline {
/* continuous build pipeline for jenkins */
agent any
environment {
path_visualstudio = 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe'
path_solutionfile = 'c:\foo\bar.sln'
}
stages {
stage ('solution') {
steps {
echo 'building solution'
bat '${env.path_visualstudio} ${env.path_solutionfile} /rebuild'
}
}
}
}
I am unable to successfully start the devenv.exe because of the following error in the console output:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 5: unexpected char: '\' # line 5, column 26.
path_visualstudio = 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe'
^
1 error
Is this a matter of incorrect excaping the slashes, or am I always supposed to use forward slashes in Jenkins regardless of platform?
Actually, you have the answer in your question: escape the slashes with another one. Using backslash instead should also work (not tested!)
Using the following groovy script in my Jenkinsfile to do some file operations for preparing my build package:
pipeline {
agent any
stages {
stage('package-windows') {
when {
expression { isUnix() == false && env.JOB_NAME == 'my-job-webapi'}
}
steps {
bat label: 'unzip all files', script: 'FOR /R .\\archive %%I IN (*.zip) DO "C:\\Program Files\\7-Zip\\7z.exe" x "%%I" -aou -o"%%~dpI\\*"'
}
}
}
}
When i run the job its failing with the following error:
\Program was unexpected at this time.
C:\Program Files (x86)\Jenkins\workspace\my-job-webapi>FOR /R .\archive \Program Files\7-Zip\7z.exe" x "~dpI\*"[Pipeline] }
For some reason its unable to recognize the drive letter C: in the path "C:\\Program Files\\7-Zip\\7z.exe". What is the right way to provide the path with windows drive letter in Groovy script ? Or is there a different way this needs to be handled ?
Just needed to use / instead of \\. C:/Program Files/7-Zip/7z.exe worked