Jenkins fails running MSBuild command - jenkins

This is my Jenkinsfile, and I have MSBuild plugin installed in Jenkins. The msbuild command below is correct as I can run it from the command line, yet Jenkins keeps failing on it. If I remove the parameter it's complaining about then it fails on next one, etc...
Jenkinsfile (saved in git repository):
pipeline {
agent {
docker 'node:7.7.3'
}
stages {
stage('Build') {
steps {
bat echo 'Checking node.js version..'
bat echo 'node -v'
bat echo 'Restore nugets..'
bat 'nuget restore mySolution.sln'
bat echo 'Building..'
bat "C:\\Program Files (x86)\\MSBuild\\14.0\\Bin\\msbuild.exe" mySolution.sln /noautorsp /ds /nologo /t:clean,rebuild /p:Configuration=Debug /v:m /p:VisualStudioVersion=14.0 /clp:Summary;ErrorsOnly;WarningsOnly /p:ProductVersion=1.0.0.${env.BUILD_NUMBER}
}
}
stage('Test') {
steps {
bat echo 'Testing..'
}
}
stage('Deploy') {
steps {
bat echo 'Deploying....'
}
}
}
post {
success {
bat echo 'Pipeline Succeeded'
}
failure {
bat echo 'Pipeline Failed'
}
unstable {
bat echo 'Pipeline run marked unstable'
}
}
}
Error:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 14: expecting '}', found '/' # line 14, column 84.
\msbuild.exe" mySolution.sln /noautorsp
^

The issue is that the entire bat argument needs to be in quotes, so:
bat "'C:\\Program Files (x86)\\MSBuild\\14.0\\Bin\\msbuild.exe' mySolution.sln /noautorsp /ds /nologo /t:clean,rebuild /p:Configuration=Debug /v:m /p:VisualStudioVersion=14.0 /clp:Summary;ErrorsOnly;WarningsOnly /p:ProductVersion=1.0.0.${env.BUILD_NUMBER}"
Otherwise, it's treating mySolution.sln as a Groovy keyword, then /noautorsp, etc. You could also avoid the full path to MSBuild.exe here by defining it as a tool in Jenkins (via the MSBuild plugin), then doing what I describe at https://stackoverflow.com/a/45592810/466874.

Related

Running playwright tests stage stuck in running state endlessly on Jenkins

I created a Jenkins pipeline that runs dockerize the frontend app, build it and run playwrite test cases.
My problem is that, the running tests stage doesn't move to the next step after running all tests.
Jenkins file:
#!groovy
pipeline {
agent any
stages {
stage('Checkout') {
steps {
echo 'Clean workspace'
cleanWs()
echo 'Checking out the PR'
checkout scm
}
}
stage('Build') {
steps {
echo 'Destroy Old Build'
echo 'Building'
sh 'make upbuild_d'
}
}
stage('Lint') {
steps {
echo 'Checking Lint'
sh 'make lint'
}
}
stage('Test') {
steps {
echo 'Running Tests ...'
sh 'make test-e2e'
}
}
}
// [StagePost] Clean after finishing
post {
always {
echo '## BEGIN ALWAYS BLOCK ##'
echo 'Destroy Build'
sh 'make destroy'
cleanWs()
echo '## END ALWAYS BLOCK ##'
}
}
}
Here is the make test-e2e in Makefile
test-e2e:
docker exec my-container bash -c 'npm run test:e2e'
And this is the test:e2e script npx playwright test --project=chromium
How can Jenkins detect that all tests are already run to execute the post steps?
This issue occurred because of this line in playwright.config.js reporter: 'html'.
This results in trying to open the test report in a browser that requires a GUI which isn't found inside the container, so the process hangs. It is fixed by updating the reporter config as reporter: [['html', { open: 'never' }]]

SonarQube Access denied in Jenkins Pipeline

I'm trying to set up my Jenkins Pipeline to work along with SonarQube, However at the building stage Im getting the following error message:
/var/jenkins_home/workspace/practica3/node_modules/sonar-scanner/bin/sonar-scanner: exec: line 59: : Permission denied
I have the next Jenkins pipeline file:
pipeline {
agent {
docker {
image 'node:17-alpine3.14'
args '-p 3001:3000'
}
}
stages {
stage('Build') {
steps {
sh 'npm install'
withSonarQubeEnv('SonarQube'){
sh "npm install sonar-scanner"
sh "npm run sonar"
}
}
}
stage('Test') {
steps {
sh 'npm run test'
}
}
}
}
My sonar-project.properties looks like this:
sonar.projectKey=nodejs-app
sonar.projectName=nodejs-app
sonar.projectVersion=1.0
sonar.sourceEncoding=UTF-8
sonar.host.url=http://localhost:9000
sonar.login=MyToken
sonar.javascript.lcov.reportPaths=coverage/lcov.info
Any Ideas? I will appreciate it.

How to stash and unstash artefacts across stages in a Jenkinsfile in declarative pipeline

I have 2 stages in a Jenkinsfile with decarative pipeline
stage("Build_Stage") {
steps {
sh './build.sh 2>&1 ; test ${PIPESTATUS[0]} -eq 0'
// The output directory is ./build. How to stash this here
}
}
stage("Upload_Artefacts_Stage") {
steps {
// How to unstash the build directory which was stashed in Build_Stage
sh './prepare_build_artefacts.sh ios 2>&1 ; test ${PIPESTATUS[0]} -eq 0'
}
}
prepare_build_artefacts.sh intakes the output of build.sh which is called across stages.
How to stash the output build directory and un-stash it in the second stage which follows the build stage?
Please see below code which will help you to stash and unstash.Note that the stash and unstash steps are designed for use with small files. For large data transfers, use the External Workspace Manager plugin, or use an external repository manager such as Nexus or Artifactory
stage("Build_Stage") {
steps {
sh './build.sh 2>&1 ; test ${PIPESTATUS[0]} -eq 0'
// The output directory is ./build. How to stash this here
// Below method will stash build directory
stash includes: "build/" , name: "Build_stash"
}
}
stage("Upload_Artefacts_Stage") {
steps {
// How to unstash the build directory which was stashed in Build_Stage
// Give path of the directory where you would like to unstash it.
dir("C:\\Data\\CI_Workspace\\${env.JOB_NAME}")
{
unstash "Build_stash"
}
sh './prepare_build_artefacts.sh ios 2>&1 ; test ${PIPESTATUS[0]} -eq 0'
}
}

using msbuild in a Jenkins multi branch project

How can I use MSBuild in a Jenkins multi-branch project?
Here's my Jenkinsfile:
pipeline {
agent any
stages {
stage('restore') {
steps {
sh "echo 'TODO RUN TEST'"
}
}
stage('build') {
steps {
bat "\"${tool 'MSBuild'}\" .\\src\\MySollutionName.sln /p:Configuration=Release /p:Platform=\"Any CPU\" /p:ProductVersion=1.0.0.${env.BUILD_NUMBER}"
}
}
stage('test') {
steps {
sh "echo 'TODO RUN TEST'"
}
}
}
}
But I'm getting an error message:
No tool named MSBuild found
Is it possible to use MSBuild in Jenkins multi-branch project?
You need to first tell Jenkins what the MSBuild tool is:
https://wiki.jenkins.io/display/JENKINS/Custom+Tools+Plugin
Have you installed the MSBuild plugin?
https://wiki.jenkins.io/display/JENKINS/MSBuild+Plugin

Jenkins Pipeline Error

I am using the pipeline plugin in Jenkins, but unable to run shell commands. I am receiving the following error:
[develop - pipeline] Running shell script
nohup: failed to run command ‘sh’: No such file or directory
The node is an Ubuntu instance.
node ('aws-ondemand') {
//println env.BUILD_NUMBER
try {
stage 'Checkout and Build'
git url: 'git#github.com:MyAndroidRepo.git',
branch: 'develop'
sh 'git submodule init'
sh 'git submodule update'
sh './gradlew clean build'
}catch (e) {
//currentBuild.result = "FAILED"
//notifyFailed()
throw e
}
}
Nevermind. Script is fine. I was injecting env variables in the build step. I removed it and now its working.

Resources