Search code examples
jenkinscontinuous-integrationjenkins-declarative-pipeline

Compiling Visual Studio 2015 solutions from Jenkins declarative pipeline


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?


Solution

  • Actually, you have the answer in your question: escape the slashes with another one. Using backslash instead should also work (not tested!)