I'm having trouble running a publishing task via ...
# pact-jvm
é
I'm having trouble running a publishing task via `gradlew`:
Copy code
java.lang.IllegalArgumentException: Invalid pact broker host specified ('${pactbroker.host:}'). Please provide a valid host or specify the system property 'pactbroker.host'.
with the command
Copy code
./gradlew testContract \
 -Ppact.verifier.publishResults=true \
 -Ppactbroker.url="<http://foo.bar>" \
 --info
Passing
pactbroker.url
using a system property gave the same result:
Copy code
./gradlew testContract \
  --info \
  -Ppact.verifier.publishResults=$PACT_PUBLISH_VERIFICATION_RESULTS \
  -Dpactbroker.url=$PACT_BROKER_URL
u
try setting
pactbroker.host
é
Got the same result with
Copy code
./gradlew testContract --info \
    -Ppact.verifier.publishResults="true" \
    -Dpactbroker.host="<http://our.broker.com|our.broker.com>"
or
Copy code
-Dpactbroker.host="<http://our.broker.com>"
My goal is to be able to inject those value from CI so teams don't have to update their code every time we enable or change a feature (e.g. enablePending). So my verifier test code is
Copy code
@PactBroker()
class ProductControllerContractVerificationTest { … }
I would like my
gradle
task to be as light as possible, e.g.:
Copy code
val testContract = task<Test>("testContract") {
    useJUnitPlatform()
    group = "verification"
    description = "Verify contracts published by consumers."

    testClassesDirs = sourceSets["testContract"].output.classesDirs
    classpath = sourceSets["testContract"].runtimeClasspath
    outputs.upToDateWhen { false }
}
And my GitLab-CI call job's
script
to be like
Copy code
script:
    - >
      ./gradlew testContract \
        --info \
        -Dpact.provider.branch="${GIT_CURRENT_BRANCH}" \
        -Dpact.provider.version="${PACT_PROVIDER_APP_VERSION}" \
        -Dpact.verifier.buildUrl="${PACT_CI_PIPELINE_URL}" \
        -Dpactbroker.enablePending="${PACT_ENABLE_PENDING_CONTRACT}" \
        -Dpactbroker.includeWipPactsSince="${PACT_INCLUDE_WIP_PACT_SINCE}" \
        -Dpactbroker.url=$PACT_BROKER_URL \
        -Ppact.verifier.publishResults="${PACT_PUBLISH_VERIFICATION_RESULTS}"
The following declaration works: • mapping all systemProperties in the task • mapping project property
pact.verifier.publishResults
to system property
Copy code
val testContract = task<Test>("testContract") {
    systemProperties = System.getProperties() as Map<String, Any>

    systemProperty(
        "pact.verifier.publishResults", System.getenv("PACT_PUBLISH_VERIFICATION_RESULTS")
            ?: properties.getOrDefault(
                "pact.verifier.publishResults", "false"
            ) as String
    )
…
}