0
votes

How do I write groovy script that executes simple shell command and update the env variable to a properties file so that it can be used later on by Email-Ext. Here is the shell command that I want to execute using groovy:

email_recipients=`cat ${WORKSPACE}/Var/Compile/Logs/set_email_recipients.properties`
echo email_recipients=${email_recipients} > email_update.prop

Once the property file email_update.prop is created, I want to add this to the Properties File Path as part of the injected environment variables.

How do I write this as part of my DSL script?

1

1 Answers

0
votes

Here is an example. You read your shell script (run.sh) from the WORKSPACE and then pick up a file with environment variables defined.

job('run-shell-script-and-update-env') {
  steps {
    shell(readFileFromWorkspace('${WORKSPACE}/run.sh'))
  }
  environmentVariables {
    propertiesFile('email_update.prop')
  }
}