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\""
Related
I have this build error saying pandoc command is not recognize, when I build my pipeline on Jenkins :
But when I run the exact same command using cmd.exe from the same repository it works perfectly :
So what's wrong here, my command pandoc is well installed and can perfectly be used from cmd.exe, why doesn't it works from Jenkins ?
Here is my Jenkins code (the part causing the error is in the "Build" stage):
pipeline {
agent any
stages {
stage('Prerequisites') {
steps {
//bat 'RMDIR C:\\wamp64\\www\\html\\doc'
bat 'MKDIR C:\\wamp64\\www\\html\\doc'
}
}
stage('Build') {
steps {
bat 'pandoc -s C:\\wamp64\\www\\index.md -o C:\\wamp64\\www\\index.html'
bat 'pandoc -s C:\\wamp64\\www\\index.md -o C:\\wamp64\\www\\index.docx'
}
}
stage('Deploy') {
steps {
bat 'COPY C:\\wamp64\\www\\index.html COPY C:\\wamp64\\www\\html\\index.html'
bat 'COPY C:\\wamp64\\www\\index.docx COPY C:\\wamp64\\www\\html\\doc\\index.docx'
}
}
}
}
Thanks for helping.
Jenkins doesn't automatically take your Windows (path) environment variables. Instead, what you need to do is to go to Jenkins -> Configure System -> Global properties -> Environment variables and add a new variable called Path. For the value, set $Path, and your path variables should start getting registered.
The issue has been discussed extensively in this question.
I try to run SonarQube analysis for a Gradle project in a Jenkins Pipeline using the following code:
stage('SonarQube') {
withGradle {
withSonarQubeEnv('SonarQube Env') {
bat "./gradlew sonarqube"
}
}
}
The Gradle plugin is installed in Jenkins but I am getting the following error:
05:15:05 D:\*\*\*\*\*\*>./gradlew sonarqube
05:15:05 '.' is not recognized as an internal or external command,
Two things are incorrect in your code. On Windows machines you have to:
use backslashes instead of slashes in paths (./command → .\command)
execute script written for Windows (gradlew is a Unix script, gradlew.bat is a Windows script)
This code should work:
stage('SonarQube') {
withGradle {
withSonarQubeEnv('SonarQube Env') {
bat '.\\gradlew.bat sonarqube'
}
}
}
Gradle Wtapper by default is provided with two script gardlew and gradlew.bat. If your project doesn't have the gradlew.bat file, execute on your Unix machine ./gradlew wrapper. The missing file will be generated.
Btw. You don't need the Jenkins Gradle plugin, when you use Gradlew Wrapper. The plugin is required when you want to provide Gradle installations for jobs, example:
stage('SonarQube') {
withGradle {
withSonarQubeEnv('SonarQube Env') {
bat "${tool(name: 'toolId', type: 'gradle')}\\bin\\gradle.bat sonarqube"
}
}
}
toolId must much the identifiers used in the Jenkins Global Tool Configuration, examples: gradle-6.X, gradle-6.8.3 etc.
Can we build the IIB Bar file( using mqsicreatebar toolkit command) without IIB installation on jenkins box that has workspace code checked out ?
No, you have to install IIB before you can use mqsicreatebar.
Here the important bits of a Jenksfile for a job that runs on Windows:
steps {
script { currentBuild.result = 'SUCCESS' }
bat '''
call "C:/Program Files/IBM/IIB/10.0.0.14/server/bin/mqsiprofile.cmd" || exit /B 1
call mqsicreatebar ...
'''
}
I am using scrippted pipeline in Jenkins and I want to compile a solution using MsBuild.
Problem is when I run it using bat command: bat ' MsBuild.exe solution.sln /p:Configuration=Debug' (which runs it as a batch file) and when the build FAILS the job doesn't fail.
It's like it doesn't recognize that the MsBuild failed to compile the solution and continues to the next steps.
How can I run MsBuild and analize the output so that if the build fails, then the job will fail too?
Thank you
Try following and see how it goes:
def msbuild = "path/to/msbuild/MsBuild.exe"
def exitStatus = bat(returnStatus: true, script: "${msbuild} solution.sln /p:Configuration=Debug")
if (exitStatus != 0){
currentBuild.result = 'FAILURE'
}
And if you don't want to execute it any further, you can throw an error if exit status is not 0:
if (exitStatus != 0){
currentBuild.result = 'FAILURE'
error 'build failed'
}
I have created a Jenkins Pipeline job. In this job I want to do the build using Ant. I have configured the Ant variable in Manage **Jenkins > Global Tool Configuration** as Ant1.9.1= D:\path_to_hybris\hybris\bin\platform\apache-ant-1.9.1.
In a freestyle jenkins Job, I know that the build.xml location can be specified as in the below screenshot:
but I am unable to understand how to specify the ant groovy script beyond this point, especially where can we mention the path to build.xml file:
def antHome = tool 'Ant1.9.1'
????
????
you can use ant wrapper in Jenkins`s pipeline groovy script.
withAnt(installation: 'LocalAnt') {
// some block
sh "ant build"
//for windows
bat "ant build"
}
Remember to configure the ant tool in the Jenkins "Global Tool Configuration" with the same name "LocalAnt".
You can try this:
def antVersion = 'Ant1.9.1'
withEnv( ["ANT_HOME=${tool antVersion}"] ) {
sh '$ANT_HOME/bin/ant target1 target2'
}
Under Windows this would look like this (I didn't test it though):
def antVersion = 'Ant1.9.1'
withEnv( ["ANT_HOME=${tool antVersion}"] ) {
bat '%ANT_HOME%/bin/ant.bat target1 target2'
}
This assumes that you have Ant configured in Jenkins with name 'Ant1.9.1'.
I needed this multiple times within the same Jenkinsfile that needs to be executed on both linux and windows agents so I created a method for it.
You can call ant like this
callAnt("-v -p")
if you add this method definition to your jenkinsfile
def callAnt(String Parameters) {
if (isUnix()) {
env.PATH = "${tool 'ant'}/bin;${env.PATH}"
sh "ant ${Parameters}"
}
else {
env.PATH = "${tool 'ant'}\\bin;${env.PATH}"
bat "ant ${Parameters}"
}
}