Hello. I've got a question regarding can-i-deploy ...
# pactflow
v
Hello. I've got a question regarding can-i-deploy step. I'm using it 2 times in my CI/CD workflows. One - when I verify whether I can merge the code, in this case I verify pact against provider's master branch, the other one - when I verify whether I can deploy the code, in this case I verify pact against provider's env. So my script looks this way:
Copy code
#!/usr/bin/env bash

echo "running can-I-deploy with the following params""
PACT_BROKER_BASE_URL: $PACT_BROKER_BASE_URL
PACT_BROKER_TOKEN: $PACT_BROKER_TOKEN
consumer: $consumer
version: $version
provider: $provider
to_environment: $to_environment
"""

if [ -z "$version" ]; then
  echo "ERROR: version cannot be empty to run can-i-deploy verification"
  exit 1
fi

command=
if [ -z "$to_environment" ]; then
  command="--pacticipant $provider --branch master"
else
  command="--provider $provider --to-environment $to_environment"
fi
echo "command = $command "
docker run --rm \
  -w "${PWD}" \
  -v "${PWD}":"${PWD}" \
  -e PACT_BROKER_BASE_URL="$PACT_BROKER_BASE_URL" \
  -e PACT_BROKER_TOKEN="$PACT_BROKER_TOKEN" \
  pactfoundation/pact-cli:0.50.0.32 \
  broker can-i-deploy \
  --pacticipant "$consumer" \
  --version "$version" \
  $command
I've found that if I want to use
--branch master
in my command I need to use
--pacticipant
, if I want to use
--to-environment
I need to use
--provider
otherwise it returns an error...Am I missing something here? If not...why cannot it be the same (provider or pacticipant) in both cases?
m
hmmm something else must be the matter. All of our examples use the format
Copy code
pact-broker can-i-deploy \
	  --pacticipant ${PACTICIPANT} \
	  --version ${GIT_COMMIT} \
	  --to-environment ${ENVIRONMENT}
v
Right, the first pacticipant is consumer. What if I want to specify the provider name in the command?
m
Why are you specifying two
--pacticipant
values in this case? I think that’s your issue
The simplest and most normal use case, is to deploy one application at a time
If you want to deploy the consumer, use the consumer name in the
--pacticipant
flag. And vice versa
v
Ok my case is here: we have a multi-tenant consumer with single-tenant providers. So when I run can-i-deploy step, I need to verify pact between the consumer and different providers. Some providers are deployed to all envs, some providers are deployed only to some envs. What I want to make sure when I deploy my consumer is that a 'valid' version of the provider is deployed to env1, env2, env3. I am going to use strategy.matrix for this:
Copy code
strategy:
  matrix:
    provider: [<provider1>]
    env: [
      "<env1>", "<env2>", "<env3>"
    ]
and I expect my command call to looks this way (in a loop for each env):
Copy code
broker can-i-deploy \
--pacticipant "$consumer" \
--version "$version" \
--provider "<provider1>"
--to-environment "<env1>"
👍 1
So I understand the idea when you specify only one pacticipant (the one you are about to deploy) and verify all pacts from pact broker. But what if I want to explicitly verify compatibility of my consumer with
exact
providers
m
I'm still not getting why you need to specify the providers in the command tho. by asking can I deploy and giving a specific application and environment, it will tell you if there are missing dependencies, or if those dependencies are incompatible.
v
ok lets I have a consumer C and it has 2 providers P1 and P2. • C is a multi-tenant service and gets deployed to a single env
prod
. • P1 is a single-tenant service and gets deployed to client1_prod, client2_prod, client3_prod envs. • P2 is a single-tenant service and gets deployed to client1_prod, client2_prod envs I will record deployment for •
P1
envs
client1_prod
,
client2_prod
,
client3_prod
P2
envs
lient1_prod
,
client2_prod
Now I need to verify if I can deploy C. I need to verify pacts C - P1 env
client1_prod
C - P1 env
client2_prod
C - P1 env
client3_prod
C - P2 env
client1_prod
C - P2 env
client2_prod
If I don't specify the provider, I need to verify <all pacts for consumer C> for envs
client1_prod
,
client2_prod
,
client3_prod
But verification C - P2 env
client3_prod
will fail, because this service will never be there