Sunday, April 3, 2016

In this post I will explain how we can set dynamic properties within a Jenkins build. I will append the current Date for the build name to demonstrate how we can achieve this.


First you need to install Groovy Script plugin. (This is just one way of doing this)

You can go to plugin manager and Install the groovy plugin.




After Installing it will look like following.



Now got to the build you configured and add a Pre-Build Steps and select "Execute system Groovy script."


Now add the following script as the body.


import hudson.model.*
  
def build = Thread.currentThread().executable
def today = new Date()
def pa = new ParametersAction([new StringParameterValue("DATE",today.toString())])
build.addAction(pa)


With the above code snippet I have added the system date to a variable called "DATE". After setting this should be accessible within the job context with the following syntax.

$DATE
${DATE}queries.

Hope this will help someone interested and please drop a comment if you have any queries.



Categories:

0 comments:

Post a Comment

Subscribe to RSS Feed Follow me on Twitter!