Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can initialize a groovy variable in a Jenkinsfile within a batch script by using the following syntax:

bat '''
set myVariable=value
'''
def myGroovyVariable = bat(script: 'echo %myVariable%', returnStdout: true).trim()

This command will set the batch variable "myVariable" to "value", and then it will retrieve the value of "myVariable" from the batch script output using the "bat" step in Groovy. It then trims any whitespace from the output and stores the result in a Groovy variable called "myGroovyVariable".