Hello, we started to use Pact on our projects and ...
# pact-jvm
m
Hello, we started to use Pact on our projects and I'm working on a Github Actions to help consumers to upload their contract to Pactflow. I would like to add the
branch
information but it does not work properly. Here is the command that was executed by the action :
Copy code
mvn au.com.dius.pact.provider:maven:4.1.11:publish -Dpact.broker.url=<https://XXXX.pactflow.io> -Dpact.broker.token=*** -Dpact.broker.authenticationScheme=*** -Dpact.publish.consumer.branchName=feat/UTO-706_contract-testing
But in Pactflow the
branch
has been set with the
93/merge
that is the merge branch generated by Github on Pull Request. Is there a known problem ou am I doing something wrong ? Thanks for your help!
t
Do you have the
maven-surefire-plugin
in your xml?
Otherwise, what you’re doing looks right to me. Do you have the environment variables
pact.publish.consumer.branchName
or
PACT_PUBLISH_CONSUMER_BRANCHNAME
set to
"93/merge"
? (If no, you could also try setting those environment variable to your desired value, as a workaround)
m
Yes surefire is executed to launch Pact Unit test and produce the pact Json file.
That is what i have done ^^ In the command, i've setted the JVM System property :
-Dpact.publish.consumer.branchName=feat/UTO-706_contract-testing
And that is precisely what it does not work.
t
Yes, I understand. I’m saying that the documentation says you can also specify the branch with the environment variable:
Copy code
pact.publish.consumer.branchName
or
Copy code
PACT_PUBLISH_CONSUMER_BRANCHNAME
So, I would: 1) Check that you’re not overriding with either of those environment variables 2) Try setting those environment variables anyway, maybe they work Otherwise it sounds like a bug to me - at least in the documentation, if not in the software.
m
I checked that the environment variable was not set before launching the maven plugin and i did set it manually but the result stay the same 😕
u
The property is
pact.provider.branch
, you can see all the properties here: https://github.com/pact-foundation/pact-jvm/blob/master/docs/system-properties.md
t
m
@uglyog Thank you but the documentation says :
Branch name for the provider from the version control system to record when publishing verification results.
But I'm not publishing verification result, i'm publishing the pact from the consumer so i don't think it will work with this property 😕
u
Oh, sorry, my mistake
m
This is the code from the `PactBrokerClient`that read the property :
Copy code
private fun branchName(config: PublishConfiguration): JsonValue {
    return config.branchName.ifNullOrEmpty {
      lookupEnvironmentValue("pact.publish.consumer.branchName")
    }.toJson()
  }
https://github.com/pact-foundation/pact-jvm/blob/master/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/PactBrokerClient.kt#L721 So it is the good one. It executes : https://github.com/pact-foundation/pact-jvm/blob/master/core/support/src/main/kotlin/au/com/dius/pact/core/support/Utils.kt#L185
Copy code
/**
   * Looks up a value from the environment, first by looking for the JVM system property with the key, then
   * looking for an environment variable with the key, then looking for the snake-cased version of the key as an
   * environment variable.
   */
  fun lookupEnvironmentValue(key: String): String? {
    return lookupEnvironmentValue(key, { k: String -> System.getProperty(k) }, { k: String -> System.getenv(k) })
  }

  /**
   * Looks up a value from the environment, first by looking for the JVM system property with the key, then
   * looking for an environment variable with the key, then looking for the snake-cased version of the key as an
   * environment variable.
   */
  fun lookupEnvironmentValue(
    key: String,
    sysLookup: (key: String) -> String?,
    envLookup: (key: String) -> String?
  ): String? {
    var value: String? = sysLookup(key)
    if (value.isNullOrEmpty()) {
      value = envLookup(key)
    }
    if (value.isNullOrEmpty()) {
      value = envLookup(snakeCase(key))
    }
    return value
  }
In my case, it will do :`System.getProperty("pact.publish.consumer.branchName")` so the only way that the value could be wrong, is that the
branchName
field is already set in the Mojo : https://github.com/pact-foundation/pact-jvm/blob/master/provider/maven/src/main/kotlin/au/com/dius/pact/provider/maven/PactPublishMojo.kt#L40
Well i finally find out the problem... it is just a version problem... The branchName property is not supported on the
4.1.11
.... facepalm2 I've just checked the documentation and it says :
Including the consumer branch when publishing [min versions 4.1.33/4.2.19/4.3.4]
I have no excuse, sorry for the inconvenience...