jenkins - increment a variable like */2.4.7 via python -
I am trying to increase the last int in one variable, and stuck on how to do it properly is. / P>
version = tree.find ('.ru branch branch / name'). Text; Sprint = Inte (version split (".") [2]) Sprint = Sprint + 1 Newverson = version.ipip (".") [0], version.ipip (".") [1], Sprint # output ('* / 2', '4', 8)
I should have output * / 2.4.8
Just divide the last part, the fastest way to do this is:
prefix, _, sprint = Version.rpartition ('.') Newversion = '{} {} ' Formatting (prefix, int (sprint) + 1)
We also get the prefix from the partition
You can also make another limit with it:
prefix, sprint = version.rsplit ('.), 1) # new version of partition =' {}. {} ' Format (prefix, int (sprint) + 1)
demo:
& gt; & Gt; & Gt; Version = '* / 2.4.7' & gt; & Gt; & Gt; Prefix, _, sprint = version. Partition ('.') & Gt; & Gt; & Gt; '{}. {} ' Format (prefix, int (sprint) + 1) '* / 2.4.8' & gt; & Gt; & Gt; Prefix, sprint = version. Resuple ('.', 1) #department only once & gt; & Gt; & Gt; '{}. {} ' Format (prefix, int (sprint) + 1) '* / 2.4.8'
Comments
Post a Comment