pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.08k stars 479 forks source link

Set consumer version from gradle CLI #1601

Closed jasondamour closed 1 year ago

jasondamour commented 2 years ago

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.

rholshausen commented 2 years ago

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

jasondamour commented 2 years ago

@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

rholshausen commented 2 years ago

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

rholshausen commented 2 years ago

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 commented 2 years ago

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')
    }
}
jasondamour commented 2 years ago

Thanks @rholshausen for looking into this.