Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins "Execute Shell Script" vars needed in post-build action specifically in send email body?

Tags:

jenkins

So I set up some vars in Execute Shell Script build action which I would like to use in my post-build action like send email's body. Is this possible without using any plugins? If not possible without plugins what are the plugins that I should use? Thanks very much,

like image 313
user2570291 Avatar asked Jun 02 '14 13:06

user2570291


People also ask

How Jenkins execute shell script as post build action?

When you configure your jenkins job there is a section where you can specify post build actions. If this plugin is not visible then you need to download it. After that you can specify the script or the contents of the script. Click on apply and run the job.

How do I run a shell script in Jenkins pipeline?

These are the steps to execute a shell script in Jenkins: In the main page of Jenkins select New Item. Enter an item name like "my shell script job" and chose Freestyle project. Press OK.


1 Answers

Not possible without plugins because:

  • Execute Shell Script and Post-build actions are run in separate environment sessions, so anything that had been set in the former is not available in the latter.

What you need is the EnvInject plugin.

  • In your Execute Shell Script step, instead of setting an environment variable, write the key-value pair to file, for example myvar=somevalue.
  • Add another build step, called Inject environment variables for your job. Give it the location of the file with the key-value pair.
  • Now that variable is available as an environment variable for the rest of the job run (including other build steps and post-build steps).
like image 103
Slav Avatar answered Oct 02 '22 06:10

Slav