pact-jvm
pact-jvm copied to clipboard
Tags are not published with the Gradle plugin when using providerTags
According to the documentation you can publish tags when verifying a contract via providerTags
. I've found that specifying providerTags
in the pact
Gradle task does not work
pact {
def gitSha = "git rev-parse --short HEAD".execute().text.trim()
logger.lifecycle("gitSha: " + gitSha)
// apply pact-specific properties https://docs.pact.io/implementation_guides/jvm/provider/gradle/#project-properties
System.setProperty("pact.showStacktrace", "true");
System.setProperty("pact.verifier.ignoreNoConsumers", "true");
broker {
pactBrokerUrl = 'https://pact-broker.docker.savagebeast.com'
}
reports {
defaultReports() // adds the standard console output
markdown // report in markdown format
json // report in json format
console
}
serviceProviders {
catalog {
terminateProviderTask = killGretty
// assume that when pact verification is run, the port is not specified via the command line
port = "$grettyPort"
fromPactBroker {
// specify the tags we want to verify here
// https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors/
selectors = latestTags('master', 'mobile-test', 'prod', 'dr')
providerTags = ['foo']
providerVersion = { gitSha }
if (gitBranch == 'master') {
enablePending = true // enable pending pacts support
}
}
}
}
When I run ./gradlew pactVerify -i -PdevDB -Ppact.verifier.publishResults=true -d
the request with providerTags
is null and the pact verification result is not tagged in the pact-broker:
16:53:58.426 [DEBUG] [au.com.dius.pact.provider.ProviderClient] Making request for provider au.com.dius.pact.provider.gradle.GradleProviderInfo@63e27c4e[providerVersion=build_agfshzjdd1dkne35s7bt3ouk3$_run_closure24$_closure42$_closure43$_closure44$_closure45@1615af63,providerTag=<null>,providerTags=<null>,brokerConfig=PactBrokerConsumerConfig(selectors=[ConsumerVersionSelector(tag=master, latest=true, consumer=null, fallbackTag=null), ConsumerVersionSelector(tag=mobile-test, latest=true, consumer=null, fallbackTag=null), ConsumerVersionSelector(tag=prod, latest=true, consumer=null, fallbackTag=null), ConsumerVersionSelector(tag=dr, latest=true, consumer=null, fallbackTag=null)], enablePending=false, providerTags=[foo]),project=project ':catalog',name=catalog,protocol=http,host=localhost,port=64683,path=/,startProviderTask=<null>,terminateProviderTask=task ':catalog:killGretty',requestFilter=<null>,stateChangeRequestFilter=<null>,createClient=<null>,insecure=false,trustStore=<null>,trustStorePassword=changeit,stateChangeUrl=<null>,stateChangeUsesBody=true,stateChangeTeardown=false,isDependencyForPactVerify=true,verificationType=REQUEST_RESPONSE,packagesToScan=[],consumers=[ConsumerInfo(name='Pact between hestia (6a00bddc) and catalog', stateChange=null, stateChangeUsesBody=true, packagesToScan=[], verificationType=null, pactSource=BrokerUrlSource(url=https://pact-broker.docker.savagebeast.com/pacts/provider/catalog/consumer/hestia/pact-version/aa83c5731bb25aa8e840dbc64bd4062eaa133159, pactBrokerUrl=https://pact-broker.docker.savagebeast.com, attributes={}, options={}, tag=null, result=PactBrokerResult(name=Pact between hestia (6a00bddc) and catalog, source=https://pact-broker.docker.savagebeast.com/pacts/provider/catalog/consumer/hestia/pact-version/aa83c5731bb25aa8e840dbc64bd4062eaa133159, pactBrokerUrl=https://pact-broker.docker.savagebeast.com, pactFileAuthentication=[], notices=[VerificationNotice(when=before_verification, text=The pact at https://pact-broker.docker.savagebeast.com/pacts/provider/catalog/consumer/hestia/pact-version/aa83c5731bb25aa8e840dbc64bd4062eaa133159 is being verified because it matches the following configured selection criteria: latest pact for a consumer version tagged 'dr', latest pact for a consumer version tagged 'master', latest pact for a consumer version tagged 'mobile-test', latest pact for a consumer version tagged 'prod' (all have the same content))], pending=false, tag=null, wip=false, usedNewEndpoint=true)), pactFileAuthentication=[], notices=[VerificationNotice(when=before_verification, text=The pact at https://pact-broker.docker.savagebeast.com/pacts/provider/catalog/consumer/hestia/pact-version/aa83c5731bb25aa8e840dbc64bd4062eaa133159 is being verified because it matches the following configured selection criteria: latest pact for a consumer version tagged 'dr', latest pact for a consumer version tagged 'master', latest pact for a consumer version tagged 'mobile-test', latest pact for a consumer version tagged 'prod' (all have the same content))], pending=false, wip=false), ConsumerInfo(name='Pact between graphql (1896a2ce) and catalog', stateChange=null, stateChangeUsesBody=true, packagesToScan=[], verificationType=null, pactSource=BrokerUrlSource(url=https://pact-broker.docker.savagebeast.com/pacts/provider/catalog/consumer/graphql/pact-version/34c9b0ea66c203af2897e2f9f8ec0772f60697aa, pactBrokerUrl=https://pact-broker.docker.savagebeast.com, attributes={}, options={}, tag=null, result=PactBrokerResult(name=Pact between graphql (1896a2ce) and catalog, source=https://pact-broker.docker.savagebeast.com/pacts/provider/catalog/consumer/graphql/pact-version/34c9b0ea66c203af2897e2f9f8ec0772f60697aa, pactBrokerUrl=https://pact-broker.docker.savagebeast.com, pactFileAuthentication=[], notices=[VerificationNotice(when=before_verification, text=The pact at https://pact-broker.docker.savagebeast.com/pacts/provider/catalog/consumer/graphql/pact-version/34c9b0ea66c203af2897e2f9f8ec0772f60697aa is being verified because it matches the following configured selection criteria: latest pact for a consumer version tagged 'dr', latest pact for a consumer version tagged 'master', latest pact for a consumer version tagged 'mobile-test', latest pact for a consumer version tagged 'prod' (all have the same content))], pending=false, tag=null, wip=false, usedNewEndpoint=true)), pactFileAuthentication=[], notices=[VerificationNotice(when=before_verification, text=The pact at https://pact-broker.docker.savagebeast.com/pacts/provider/catalog/consumer/graphql/pact-version/34c9b0ea66c203af2897e2f9f8ec0772f60697aa is being verified because it matches the following configured selection criteria: latest pact for a consumer version tagged 'dr', latest pact for a consumer version tagged 'master', latest pact for a consumer version tagged 'mobile-test', latest pact for a consumer version tagged 'prod' (all have the same content))], pending=false, wip=false)]]:
16:53:58.427 [DEBUG] [au.com.dius.pact.provider.ProviderClient] method: POST
When I run ./gradlew pactVerify -i -Ppact.verifier.publishResults=true -Dpact.provider.tag=foo -PdevDB -d
, I see the following entry in the gradle output and the pact verification result is tagged in the pact-broker:
17:00:47.531 [DEBUG] [au.com.dius.pact.core.pactbroker.PactBrokerClient] Pushed tag foo for provider catalog and version 3b305ae4
The project I'm using is configured with the following:
au.com.dius.pact.provider:gradle:4.1.20'
------------------------------------------------------------
Gradle 5.4.1
------------------------------------------------------------
Build time: 2019-04-26 08:14:42 UTC
Revision: 261d171646b36a6a28d5a19a69676cd098a4c19d
Kotlin: 1.3.21
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 11.0.9 (AdoptOpenJDK 11.0.9+11)
OS: Mac OS X 10.15.7 x86_64
Released 4.1.26 with the fix
I just tried this with 4.1.26 and still could not get a tag published using providerTags
@uglyog I don't think this is specifically related to Gradle. I also have this same problem with maven using version 4.1.28. Unfortunately, this is the latest version I can use due to my project being a java 8 project. Other projects within my company that are using the latest version do not have this issue, but like I say given I have to use a Java 8 supported version the issue persists.
yeah, the issue doesn't appear to be gradle specific. I am using pact jvm 4.2.14. Tried publishing provider tag with PendingPacts enabled but no luck.
@PactBroker(url = "${pactbroker.url}",
authentication = @PactBrokerAuth(username = "${pactbroker.auth.username}", "${pactbroker.auth.password}"
providerTags = "master",
enablePendingPacts = "true"
)
As a work around I was able to add tags through create-version-tag
from cli tool or pact.provider.tag
system property but it would be good to get providerTags working.
This issue is due to:
The providerTags
value is used to fetch Pacts from the pact broker. It is passed on to the broker and not used anywhere else.
The pact.provider.tag
system property is used when publishing verification results. If set, the tags will be published first before the verification results.
Thanks for the clarification @uglyog. So, the providerTags
is working the way it is intended to be from what you are saying? I misinterpreted the line "You also need to provide the tags that will be published with your provider's verification results."
from the documentation to think providerTags
would be used while publishing verification results. Maybe worth rephrasing that line in the documentation or adding the additional info you mentioned above would help I think.
I'm just stating the reason for the current behaviour, but it is not ideal and needs to be fixed.