Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing data between build steps in Jenkins

Tags:

I'd like to do something along the lines of:

This is overly simple and just demonstrates what I'd like to do. Basically, I want to be able to store and access variables within a single job scope between multiple build steps. Also, I can get around by storing the data to a file and reading it later, but I'd like something easier and less 'hacky'

Build Step #1 - Execute shell

$START=timestamp 

Build Step #2 - Run another job

Build Step #3 - Execute Shell

$END=timestamp TIME_LAPSED=$END-$START (post lapsed time somewhere) 
like image 746
jcol Avatar asked Mar 13 '14 00:03

jcol


People also ask

How do you transfer workspace and environment variables in a pipeline to the next job?

Under Build Environment check Set environment variables through a file. give the path of that file here. If the environment variable is created in the first job then again you can save all the environment variable in a file and browse it using the above method. Install this plugin and go to job configuration paeg.


1 Answers

One thing remains between shells: the workspace.
Simple and stupid solution: use file(s)!

Huge additional advantage: it works when you split your job in several jobs and use the Clone Workspace plugin

Build Step #1 - Execute shell

START=timestamp ... echo $START > env_start.txt 

...

Build Step #3 - Execute Shell

START=`cat env_start.txt` END=timestamp TIME_LAPSED=$END-$START 
like image 77
Destroyica Avatar answered Sep 24 '22 01:09

Destroyica