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".
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
Asked: 2023-06-08 13:31:00 +0000
Seen: 16 times
Last updated: Jun 08 '23
How to choose specific parameters while selecting inputs in Jenkins (Groovy) Pipeline?
How to modify the node label in Jenkins once the job has been completed successfully?
What are the typical approaches found in a Gradle build script?
How can a list of objects in Groovy be created from Json?
How to provide the workspace path as a file to setReportDir in XmlTestRunListener using groovy?
What is the method to invoke a function within Gradle's `pluginManagement {}` section?
What is the reason for the convertibility of variable types in a Groovy class?