I have a contract that we can publish to the pact flow broker okay when running mvn pact:publish -Dpactbroker.auth.token=myToken. However, the same contract and maven command gives us an authentication error when running it from Jenkins. Not sure what could be wrong as the step that comes next and does the verification of the contract works successfully and using the same token.
This is the version we're using:
<pact.version>4.2.14</pact.version>
<pact.plugin.version>4.0.10</pact.plugin.version>
<maven.surefire.version>3.0.0-M5</maven.surefire.version>
And here our jenkins file
node {
def git_commit
def mvnHome = tool name: 'maven3.6.0'
stage(name: 'Checkout') {
git credentialsId: ‘someCredentials’, url: “my.git", branch: "$branch_name"
sh "git rev-parse HEAD > commit"
git_commit = readFile('commit').trim()
}
stage(name: 'Compile') {
sh "$mvnHome/bin/mvn clean package -DskipTests"
}
stage(name: 'Pact Generate Contracts') {
sh "$mvnHome/bin/mvn -Dtest=com.hmhco.viaductservice.pact.consumer.*Test test"
}
stage(name: 'Pact Publish Contracts Tests') {
sh "$mvnHome/bin/mvn pact:publish -Dpactbroker.auth.token=myToken”
}
stage(name: 'Pact Verify Tests') {
sh "$mvnHome/bin/mvn -Dpactbroker.auth.token=myToken -Dtest=com.hmhco.viaductservice.pact.provider.*Test test"
}
}
It's working now. As the publishing step comes from the maven pact jvm plugin we needed to add a way for it to get the token by adding this line to the plugin.
<pactBrokerUrl>https://hmhco.pact.dius.com.au/</pactBrokerUrl>
So now we have
<plugin>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-provider-maven</artifactId>
<version>${pact.plugin.version}</version>
<configuration>
<pactDirectory>target/pacts</pactDirectory>
<pactBrokerUrl>https://hmhco.pact.dius.com.au/</pactBrokerUrl>
<!--suppress UnresolvedMavenProperty -->
<pactBrokerToken>${pactbroker.auth.token}</pactBrokerToken>
<projectVersion>${project.version}</projectVersion>
<trimSnapshot>true</trimSnapshot>
</configuration>
</plugin>