pact-jvm icon indicating copy to clipboard operation
pact-jvm copied to clipboard

Set consumer version from gradle CLI

Open jasondamour opened this issue 2 years ago • 6 comments

Hello,

Maybe I am misunderstanding something. In the pact foundation docs, one of the recommendations is to version the published pacts from the consumer with unique versions (https://docs.pact.io/getting_started/versioning_in_the_pact_broker#rules).

However, the gradle plugin does not have any documented support for setting consumer version via CLI, like project or system property. So how can I pass git commit info into the plugin.

I cannot add the git info plugin to my projects.

Thank you.

jasondamour avatar Aug 30 '22 00:08 jasondamour

It is documented here: https://github.com/pact-foundation/pact-jvm/tree/master/provider/gradle#including-the-consumer-branch-when-publishing-min-versions-41334219434

rholshausen avatar Aug 30 '22 06:08 rholshausen

@rholshausen I tried this again, it doesn't seem to be working. Here is the full command our CI server is running:

./gradlew --info --stacktrace --console=auto --no-daemon 
pactVerify 
-Ppact.verifier.publishResults=true 
-Dpact.verifier.buildUrl=https://gitlab.[masked]/-/pipelines/626854602 
-Dpact.provider.branch=[masked] 
pactTests 
pactPublish 
-Dpact.publish.consumer.buildUrl=https://gitlab.[masked]/-/pipelines/626854602 
-Dpact.publish.consumer.branchName=[masked] 
-Dpact.publish.consumer.version=c3982fce0f665f4116ef9ab788efb720ea302b88

And here is the error:

> Task :pactPublish FAILED
Publishing 'CONSUMER-PROVIDER.json' ... 
FAILED! 409 Conflict - 
{"error":"Cannot change the content of the pact for CONSUMER version 
0.0.1-SNAPSHOT and provider PROVIDER, as race conditions will cause unreliable 
results for can-i-deploy. Each pact must be published with a unique consumer version 
number. For more information see https://docs.pact.io/go/versioning"}
FAILURE: Build failed with an exception.

It seems to take the version from gradle.properties regardless of system property

jasondamour avatar Aug 30 '22 16:08 jasondamour

What version of Pact-JVM Gradle plugin are you using?

rholshausen avatar Aug 30 '22 23:08 rholshausen

Actually, looks like a bug. If the consumerVersion property is not set, it will set it to the version from the build, and then won't get the value from the system property because it is set to the version from the build.

rholshausen avatar Aug 31 '22 04:08 rholshausen

You can work around this by setting the consumerVersion property in the publish block in your gradle build. I.e. something like

pact {
    publish {
      consumerVersion = System.getProperty('pact.publish.consumer.version')
    }
}

rholshausen avatar Aug 31 '22 04:08 rholshausen

Thanks @rholshausen for looking into this.

jasondamour avatar Aug 31 '22 05:08 jasondamour