Hi all. Apologies, if it’s not the right channel, ...
# general
v
Hi all. Apologies, if it’s not the right channel, but I have been trying to publish our contracts to PactFlow. The following command works and publishes the contracts from my local machine but it fails with the following error from the CI. Can you please suggest what could be the issue? Command:
Copy code
docker run --rm \
  -w "${PWD}" \
  -v "${PWD}:${PWD}" \
  -e PACT_BROKER_BASE_URL \
  pactfoundation/pact-cli:latest \
  broker publish "${PWD}/build/pacts" \
  --consumer-app-version "$PACT_VERSION" \
  --branch "$GIT_BRANCH" \
  --broker-base-url "$PACT_BROKER_BASE_URL" \
  --broker-token "$PACTFLOW_TOKEN" \
Error on CI:
Copy code
Specified pact file '/godata/pipelines/currency-conversion-library/currency-conversion-library/build/pacts' does not exist. This sometimes indicates one of the arguments has been specified with the wrong name and has been incorrectly identified as a file path.
I can provide more logs if needed. Currently I have checked everything I could think of, including whether the environmental variables are set or the pacts folder has a json file in it. The only difference between my local machine and GoCD pipeline is the docker version. (My machine runs v20, while GoCD runs v19). Can you please suggest what else I can try to check here? Or is there any other way of publishing pacts from CI/CD other than this docker image
y
Is there pacts in the folder you are targeting on the machine before mounting in the imagine? Can you output or see build artefacts, or can you ssh into your building machine and run the command and inspect the container. I think you would need to remove the rm command to avoid killing the container to inspect and pull any files with docker cp
v
Yes, there are pacts in the targeted folder. Not sure if the attached volumes takes them too. There is no reason for the volume to ignore that file as it works just fine locally. Unfortunately, I cannot ssh into the machine running these as it’s a disposable agent in CI/CD. Think each agent runs in a container, and this problem might be caused by running docker command in docker container
But there is not other option I can think of, other than installing the pact cli on each build, which is not ideal I think
y
The CLI is available standalone or you can publish manually via an API call https://docs.pact.io/pact_broker/client_cli which may help, if you are in Dockerception (DockerInDocker)
v
I couldn’t find docs for publishing manually via API. Is it supposed to be on this page?
y
https://docs.pact.io/pact_broker/publishing_and_retrieving_pacts#publishing I just searched publishing pacts, this is the first result. The exact bit you'd be looking for is referenced in this section https://docs.pact.io/pact_broker/publishing_and_retrieving_pacts#publish-using-http-requests We've always advocated for use of the cli tools directly over the apis, but there is duplication, repitition and omissions across the docs that we are looking to address to make a cohesive experience. However in defence of the documentation, the search functionality is pretty good and is quicker than waiting for a slack reply. All feedback welcome :)
v
Yeah, apologies. I have been frustrated by this last couple days, so probably my first instinct should have been google search. 🙂 Which eventually led me to this page anyways, but was hoping maybe you have some better sources available. Thanks again for the support
y
Sorry, I meant a search in the top right of https://docs.pact.io as we pull in all the readmes from the repos and display them on the site so it's one of the best ways to search across the docs. Google is a bit of a Wild West sometimes. Can appreciate the frustrations, so no need to apologise my friend
I can point you to examples in code of calling the api directly via bash, albeit not for that endpoint but it may help. This is for a provider contract publish https://github.com/pactflow/example-bi-directional-provider-restassured/blob/master/scripts/publish.sh
m
So i’m very inclined to trust the error. One thing you can do, is add
--verbose
to the command to see if it gives you any additional insights
If you can please print out (prior to running the docker command) the value of
${PWD}
so we see what the mapping is
I’d also like to see an
ls -la
on
/godata/pipelines/currency-conversion-library/currency-conversion-library/build/pacts
in my experience, these types of errors tend to be small pipeline problems that’n aren’t visible - e.g. maybe the pact test itself is failing and is not producing the file or something else is cleaning up between steps.