How to use local variable value in bat statement in Jenkins pipeline

10,037 views
Skip to first unread message

Yogesh Bhole

unread,
Dec 15, 2016, 6:29:44 AM12/15/16
to Jenkins Users
Hello,

I use bat command in Jenkins pipeline which launches MSBUild. But the parameter used namely "buildconfiguration" is not expanded. You may ignore error solution file not found. What I want to use the command executed the value of varibale "buildconfiguration"

Anyone has a solution for this.

Thanks in advance.

Best Regards !



Pipeline code
---------------

def buildconfiguration = 'Debug'

node('master')
{
  stage('one')
  {
    bat '"%ProgramFiles(x86)%\\MSbuild\\14.0\\bin\\MSBuild.exe" Tools\\MailboxRefill\\Mailbox.sln /property:Configuration=${buildconfiguration} /target:Build /nologo /clp:ErrorsOnly /verbosity:minimal /p:RunCodeAnalysis=false /p:WarningLevel=1'
  }     
    
}



Output
----------
Started by user admin
[Pipeline] node
Running on master in D:\Software\Z-Tools\TestPipeline
[Pipeline] {
[Pipeline] stage
[Pipeline] { (one)
[Pipeline] bat
[TestPipeline] Running batch script

D:\Software\Z-Tools\TestPipeline>"C:\Program Files (x86)\MSbuild\14.0\bin\MSBuild.exe" Tools\MailboxRefill\Mailbox.sln /property:Configuration=${buildconfiguration} /target:Build /nologo /clp:ErrorsOnly /verbosity:minimal /p:RunCodeAnalysis=false /p:WarningLevel=1 
MSBUILD : error MSB1009: Project file does not exist.
Switch: Tools\MailboxRefill\Mailbox.sln
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE


Yogesh Bhole

unread,
Dec 15, 2016, 6:31:25 AM12/15/16
to Jenkins Users
Problem here is command uses ${buildconfiguration} instead of value of buildconfiguration variable. How to solve this ?

Slide

unread,
Dec 15, 2016, 7:41:20 AM12/15/16
to Jenkins Users
You need to use double quotes for groovy to replace the variable in the string.

bat "\"%ProgramFiles(x86)%\\MSbuild\\14.0\\bin\\MSBuild.exe\" Tools\\MailboxRefill\\Mailbox.sln /property:Configuration=${buildconfiguration} /target:Build /nologo /clp:ErrorsOnly /verbosity:minimal /p:RunCodeAnalysis=false /p:WarningLevel=1"

String interpolation only works with double quoted strings.  



--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/bc97e121-b76e-4a28-a409-c92ae3240310%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yogesh Bhole

unread,
Dec 16, 2016, 7:33:30 AM12/16/16
to jenkins...@googlegroups.com
Thanks Slide.

To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/Pr150mhNcB8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVd3ajoC_2GZ%3Dvyqo7VKosjBcSuN3EdDgjMg6o2TD8inKA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages