Here’s how I do it using the “build-name-setter” and “Post_build_task” plugins:
The “build-name-setter” plugin can read a value from a property file in the workspace. It reads it twice during a job run; first before any build tasks are executed, then again after all build tasks complete successfully. My ant build generates our desired build name and writes it to a file named “version.properties” in the form “product.version=ACME-1.0_0052”. That version.properties file actually gets used for our solaris packaging, but I have a build step that copies it to the jenkins workspace so that I can also use it to set the build name in jenkins so they match.
1. Configure build-name-setter to read a property file. “Build Name” field should have the following:
${PROPFILE,file=”version.properties”,property=”product.version”}
NOTE: The first time you run the job, the version.properties file will not yet exist in the workspace, so the job will fail since it can’t find the file. No big deal since you will have a post-build task that will then create one for you (explained later). If you don’t want the first build to fail because of this, simply create the version.properties file in the workspace (on every node it can run on) ahead of time with this: “product.version=BUILD_IN_PROGRESS”. I’ve intended to try to find a plugin that can create the file in the workspace before the build-name-setter runs, but it hasn’t been a high enough priority for me yet. ;-)
2. After my ant build step, I created a build step that simply copies the version.properties file (generated from my ant build) to the ${WORKSPACE}. The build-name-setter will read that file again after all build steps complete successfully and set the build name. Note that if any build steps fail, the build name will remain “BUILD_IN_PROGRESS” (pros and cons to that).
3. Create a “Post build task” that will change the value of the “product.version” property back to “BUILD_IN_PROGRESS” for the next build.
Log text field: version.properties
Script: echo product.version=BUILD_IN_PROGRESS > ${WORKSPACE}/version.properties
-Jeff Ng
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
jenkinsci-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/6wVJZtBQI1M/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
How is the text file ABC.txt getting created (manually, script, etc.)?
Umesh,
All you need to do is create a build step to write the string “product.version=YOUR-BUILD-NUM” to a file in the workspace (e.g. version.properties). From your original post, I assume you already have (or know how to write) a script/batch file to parse out the “builddate” from your text file. Just have the script print the string I mentioned and redirect ( > ) it to ${WORKSPACE}/version.properties. The build-name-setter plugin will do the rest.