Unique name (current date+new build number) for build in jenkins Job

30 views
Skip to first unread message

Pradeep Drall

unread,
Feb 9, 2019, 2:16:55 AM2/9/19
to Jenkins Users

Hi,

 

I would like to save the build file (ipa and apk file) with unique name (like current date+new build number), build number should be reset every day based on Jenkins job like

20190209.1

20190209.2

20190209.3

20190209.4

 

20190210.1

20190210.2

20190210.3

20190210.4

I tried in build name setter plugin but couldn't reset build number every day.

 

This functionality is available in TFS like $(date:yyyyMMdd)$(rev:.r).


Please suggest me how to implement this approach in jenkins job.


Regards,

Pradeep

Martin d'Anjou

unread,
Feb 9, 2019, 11:46:36 AM2/9/19
to Jenkins Users
Hello Pradeep,

You could use the Run Selector plugin to get the previous build, and determine where you are in the sequence based on that and on the current time of day.
It returns a RunWrapper instance, which you can query using many methods, including methods that you can use to determine if you are at the first build of the day.

Hope this helps,
Martin

Baptiste Mathus

unread,
Feb 10, 2019, 8:05:50 AM2/10/19
to jenkins...@googlegroups.com
IMO, do not do that.
I think you are going to suffer a lot from trying to maintain that system, like never ever have intermediate builds deleted or whatever that would screw up your counting system at some point (given it's generally very easy to delete a build).
This seems like unnecessary headaches :).

Why not simply use some extended form for timestamping, until minute, or even second?

My 2 cents.
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/a58984b7-c3a6-45bd-bc56-b3aaef831fc3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Martin d'Anjou

unread,
Feb 10, 2019, 11:43:52 AM2/10/19
to Jenkins Users
Baptiste is right. If the most recent build gets deleted from the build history, it will mess things up.

If you always keep the most recent build and never delete it, then it should work.

If you need to delete build history, then you should use an external system to provide the daily resetting sequence number. You can do this with a database but it is more work.

Martin

Pradeep Drall

unread,
Feb 10, 2019, 12:03:47 PM2/10/19
to jenkins...@googlegroups.com
Hi, 

Thanks for your email. 

I will not remove any previous build history. 

I am trying to get build name (current date + sequence) with run selector plugin but couldn't get succeed. Can you please share me code or screen shot, if possible. 

Thanks & regards,
Pradeep Kumar Drall
919711940167
skype - pradeep.kumar2607


Martin d'Anjou

unread,
Feb 16, 2019, 8:20:24 AM2/16/19
to Jenkins Users
Get the basic information such as the previous build number and the time the previous build started:

def runWrapper = selectRun job: 'pipeline-test', selector: permalink('lastBuild') 
echo runWrapper.getNumber().toString()
echo runWrapper.getStartTimeInMillis().toString()

The rest you have to compute with more code. You probably have to do null checks if runWrapper ends up being null.

Hope this helps,
Martin
Reply all
Reply to author
Forward
0 new messages