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

Build insignificant version when suppliyng scope, for Jenkinsfile declarative pipeline? #60

Closed
ieugen opened this issue Dec 12, 2017 · 7 comments
Milestone

Comments

@ieugen
Copy link

ieugen commented Dec 12, 2017

Hello,

How can I make reckon generate insignificant versions when supplying an (empty) stage ?

I'm using reckon to build continuous integration with Jenkins Pipeline via Jenkinsfile and I (believe I) need it to generate insignificant versions when not supplying a scope.

I have configured reckon like this:

reckon {
    normal = scopeFromProp()
    preRelease = stageFromProp('dev', 'rc', 'final')
}

And in my Jenkinsfile I have something like this:

pipeline {
  agent any
  environment { }
  parameters {
    string(name: 'releaseScope', defaultValue: 'minor', description: 'Reckon (gradle plugin) release scope.')
    string(name: 'releaseStage', defaultValue: 'dev', description: 'Reckon (gradle plugin) release stage.')
  }

  stages {
    stage('Checkout') {     steps {    checkout scm    }    }

    stage('Build'){
      steps {
        echo "Building... ${env.BRANCH_NAME}"
        sh "./gradlew clean build -Preckon.scope=${params.releaseScope} -Preckon.stage=${params.releaseStage} --stacktrace"
      }
    }

The issue that I'm having is that with default build triggering, the stage is set to 'dev' and that creates a significant version with a tag and everything, which is not something I wish to have when building non-final versions.

I run it the build with the above configuration, this is executed:

./gradlew clean build -Preckon.scope=minor -Preckon.stage=dev --stacktrace

It gives me a version like this 1.8.0-dev.1 .

I have tried not to supply the stage, or supply an empty string but it does not work:

./gradlew clean build -Preckon.scope=minor -Preckon.stage= --stacktrace
.....
Stage "" is not one of: [rc, dev, final]

Thank you,

p.s. You're awesome for making reckon and all the other stuff.

@ieugen
Copy link
Author

ieugen commented Dec 12, 2017

I've managed to figgure out a workaround by doing some groovy string interpolation:

${params.releaseScope ? '' : '-Preckon.stage=' + params.releaseStage }

I think it would be nice to treat empty string as non-specified and I believe the code responsible for this is here:

  public PreReleaseStrategy stageFromProp(String... stages) {
    Set<String> stageSet = Arrays.stream(stages).collect(Collectors.toSet());
    BiFunction<VcsInventory, Version, Optional<String>> supplier =
        (inventory, targetNormal) ->
            Optional.ofNullable(project.findProperty(STAGE_PROP)).map(Object::toString);
    return new StagePreReleaseStrategy(stageSet, supplier);
}

It makes Optional.ofNullable() from an empty string. It would be nice to filter empty strings props, don't you think?

https://github.com/ajoberstar/reckon/blob/master/reckon-gradle/src/main/java/org/ajoberstar/reckon/gradle/ReckonExtension.java

@ajoberstar
Copy link
Owner

Thanks for providing all of the feedback and issues so far. Glad to have someone interested in using the plugin.

I agree about changing it to treat an empty stage (probably the same for scope) as an empty Optional. I'll mark this as an enhancement to pull in in the next release. If you have time, you're certainly welcome to submit a PR. Otherwise, I'll tackle it when I do my next round of fixes to reckon.

@ajoberstar ajoberstar modified the milestones: 0.2.1, 0.3.0, 0.4.0 Dec 13, 2017
@cduque89
Copy link

cduque89 commented Jan 8, 2018

Hi @ajoberstar.

About this issue as well, how can we only run the reckon plugin on the jenkinspipeline?

Basically on our local development environment we don't want to generate .jar files with the reckon version. Only on the jenkins pipeline prior to do a release we want to use the reckon plugin.

Do you have any suggestion for this behaviour?

Thanks for the help.

@ieugen
Copy link
Author

ieugen commented Jan 8, 2018

Hi @cduque89 , how you build the jar name is not reckon part. It's gradle part . Search the web.
[1] https://stackoverflow.com/questions/31405818/want-to-specify-jar-name-and-version-both-in-build-gradle

@ieugen
Copy link
Author

ieugen commented Jan 8, 2018

@ajoberstar : I tried to fix the bug but did not manage. It's not fixable from that place. I did not have time to look deeper into this. Sorry.

@ajoberstar
Copy link
Owner

No problem @ieugen.

@ajoberstar
Copy link
Owner

@cduque89 Is the JAR name (as @ieugen mentions) what you were referring to for your local development? If not, what do you want the version to look like locally?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants