Ask Your Question
3

What is the method for initializing a groovy variable in a jenkinsfile within a batch script?

asked 2023-06-08 13:31:00 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-06-08 13:36:03 +0000

qstack gravatar image

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".

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-08 13:31:00 +0000

Seen: 16 times

Last updated: Jun 08 '23