Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-34085] Added support for Versionnumber Plugin (https://wiki.jenkins-ci.org/d… #818

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
job('example') {
wrappers {
versionNumber('1.0.0.${BUILDS_ALL_TIME}', 'VERSION') {
startDate()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to find a better example with some values instead of just calling all methods without options

prefixVariable('')
buildsToday()
buildsThisWeek()
buildsThisMonth()
buildsThisYear()
buildsAllTime()
skipFailedBuilds(false)
displayBuildName(true)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package javaposse.jobdsl.dsl.helpers.wrapper

import javaposse.jobdsl.dsl.Context

class VersionNumberContext implements Context {

String format
String nameVariable
String prefixVariable
boolean skipFailedBuilds
boolean displayBuildName
String startDate
String buildsToday
String buildsThisWeek
String buildsThisMonth
String buildsThisYear
String buildsAllTime

/**
* @param format Version Number Format String
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have a look at other contexts for the expected GroovyDoc. Use one sentence to describe the option and do not use the @param tags.

* @param nameVariable The version number will be stored in the environment variable specified here.
*/
VersionNumberContext(String format, String nameVariable) {
this.format = format
this.nameVariable = nameVariable
}

/**
* @param prefixVariable The prefix variable name is the environment variable specified here
* to allow using the same build numbers for all the release tags.
*/
void prefixVariable(String prefixVariable) {
this.prefixVariable = prefixVariable
}

/**
* @param skipFailedBuilds Don't increment builds today / this month / this year / all time after a failed build.
*/
void skipFailedBuilds(boolean skipFailedBuilds = true) {
this.skipFailedBuilds = skipFailedBuilds
}

/**
* @param displayBuildName Use the formatted version number for build display name.
*/
void displayBuildName(boolean displayBuildName = true) {
this.displayBuildName = displayBuildName
}

/**
* @param startDate The date the project began, in the format yyyy-MM-dd. This is used in calculating the
* number of months and years since the beginning of the project.
*/
void startDate(String startDate) {
this.startDate = startDate
}

/**
* @param buildsToday Number of builds today
*/
void buildsToday(String buildsToday) {
this.buildsToday = buildsToday
}

/**
* @param buildsThisWeek Number of builds this week
*/
void buildsThisWeek(String buildsThisWeek) {
this.buildsThisWeek = buildsThisWeek
}

/**
* @param buildsThisMonth Number of builds this month
*/
void buildsThisMonth(String buildsThisMonth) {
this.buildsThisMonth = buildsThisMonth
}

/**
* @param buildsThisYear Number of builds this year
*/
void buildsThisYear(String buildsThisYear) {
this.buildsThisYear = buildsThisYear
}

/**
* @param buildsAllTime Number of builds since the start of the project
*/
void buildsAllTime(String buildsAllTime) {
this.buildsAllTime = buildsAllTime
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -661,4 +661,33 @@ class WrapperContext extends AbstractExtensibleContext {
jiraFilter(context.filter ?: '')
}
}

/**
* Generate a version number.
*
* @since 1.45
*/
@RequiresPlugin(id = 'versionnumber', minimumVersion = '1.6')
void versionNumber(String format, String nameVariable, @DslContext(VersionNumberContext) Closure closure = null) {

Preconditions.checkNotNull(format, 'Please specify format')
Preconditions.checkNotNull(nameVariable, 'Please specify name variable')

VersionNumberContext context = new VersionNumberContext(format, nameVariable)
ContextHelper.executeInContext(closure, context)

wrapperNodes << new NodeBuilder().'org.jvnet.hudson.tools.versionnumber.VersionNumberBuilder' {
versionNumberString(context.format ?: '')
projectStartDate(context.startDate ?: '')
environmentVariableName(context.nameVariable ?: '')
environmentPrefixVariable(context.prefixVariable ?: '')
oBuildsToday(context.buildsToday ?: '')
oBuildsThisWeek(context.buildsThisWeek ?: '')
oBuildsThisMonth(context.buildsThisMonth ?: '')
oBuildsThisYear(context.buildsThisYear ?: '')
oBuildsAllTime(context.buildsAllTime ?: '')
skipFailedBuilds(context.skipFailedBuilds)
useAsBuildDisplayName(context.displayBuildName)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1488,4 +1488,83 @@ class WrapperContextSpec extends Specification {
'key1' | 'key2' | 'key3' | null | 'key1' | 'key2' | 'key3' | ''
'key1' | 'key2' | 'key3' | 'key4' | 'key1' | 'key2' | 'key3' | 'key4'
}

def 'call versionNumber'() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about this, I didn't review your test case, would you mind adding another TestCase for call versionNumber with all options'

when:
context.versionNumber('', '') {
}

then:
with(context.wrapperNodes[0]) {
name() == 'org.jvnet.hudson.tools.versionnumber.VersionNumberBuilder'
children().size() == 11
children()[0].name() == 'versionNumberString'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no need to reference all children by index, the order is not relevant in this case. See the other tests for the expected syntax, e.g. versionNumberString[0].value() == ''

children()[0].value() == ''
children()[1].name() == 'projectStartDate'
children()[1].value() == ''
children()[2].name() == 'environmentVariableName'
children()[2].value() == ''
children()[3].name() == 'environmentPrefixVariable'
children()[3].value() == ''
children()[4].name() == 'oBuildsToday'
children()[4].value() == ''
children()[5].name() == 'oBuildsThisWeek'
children()[5].value() == ''
children()[6].name() == 'oBuildsThisMonth'
children()[6].value() == ''
children()[7].name() == 'oBuildsThisYear'
children()[7].value() == ''
children()[8].name() == 'oBuildsAllTime'
children()[8].value() == ''
children()[9].name() == 'skipFailedBuilds'
children()[9].value() == false
children()[10].name() == 'useAsBuildDisplayName'
children()[10].value() == false
}
1 * mockJobManagement.requireMinimumPluginVersion('versionnumber', '1.6')
}

def 'call versionNumber with all options'() {
when:
context.versionNumber('1.0.0.${BUILDS_ALL_TIME}', 'VER') {
startDate('1970-01-02 03:04:05.6 UTC')
prefixVariable('PFX')
buildsToday('1')
buildsThisWeek('2')
buildsThisMonth('3')
buildsThisYear('4')
buildsAllTime('5')
skipFailedBuilds(false)
displayBuildName(false)
}

then:
with(context.wrapperNodes[0]) {
name() == 'org.jvnet.hudson.tools.versionnumber.VersionNumberBuilder'
children().size() == 11
children()[0].name() == 'versionNumberString'
children()[0].value() == '1.0.0.${BUILDS_ALL_TIME}'
children()[1].name() == 'projectStartDate'
children()[1].value() == '1970-01-02 03:04:05.6 UTC'
children()[2].name() == 'environmentVariableName'
children()[2].value() == 'VER'
children()[3].name() == 'environmentPrefixVariable'
children()[3].value() == 'PFX'
children()[4].name() == 'oBuildsToday'
children()[4].value() == '1'
children()[5].name() == 'oBuildsThisWeek'
children()[5].value() == '2'
children()[6].name() == 'oBuildsThisMonth'
children()[6].value() == '3'
children()[7].name() == 'oBuildsThisYear'
children()[7].value() == '4'
children()[8].name() == 'oBuildsAllTime'
children()[8].value() == '5'
children()[9].name() == 'skipFailedBuilds'
children()[9].value() == false
children()[10].name() == 'useAsBuildDisplayName'
children()[10].value() == false
}
1 * mockJobManagement.requireMinimumPluginVersion('versionnumber', '1.6')
}
}