Regarding to `pact broker` or `pactflow` failures ...
# pact-broker
s
Regarding to
pact broker
or
pactflow
failures (down for maintenance) what would happen when someone publishes, verifies or executes can-i-deploy commands? Does that build fail?
m
Are you asking, what is the behaviour of the CLI if they are down? They would fail, that would be my expectation
s
Okay 👍
m
Were you expecting something else?
IMO you always need a way to build an escape hatch for CI in case a system is down.
t
I've never seen this happen in all of my years of using pact. I have seen Jenkins go down many many times 😅
😆 2
s
Actually our
devOps
are responsible for the pact broker hosting. We upgraded the docker version to one of the latest versions and we started getting message like
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
I think this is because of some config issue from
devOps
side I was curious how that impact our CI/CD pipeline and it seems consumers pipeline did not break even though pact publish stage throw error/exception but provider build/pipeline failed due to pact broker connectivity issue
m
I was curious how that impact our CI/CD pipeline and it seems consumers pipeline did not break even though pact publish stage throw error/exception
Interesting. I’d expect my consumer pipeline to fail if that happened, worth checking to avoid future logic issues with your pipelines (e.g. if your build doesn’t fail but the publish wasn’t successful, you might get strange results further down the deployment pipeline that might be hard to reason about)
b
The “break glass” in the can-i-deploy situation is to run a one off build with the env var
PACT_BROKER_CAN_I_DEPLOY_DRY_RUN=true
consumers pipeline did not break even though pact publish stage throw error/exception
This is surprising. There are retries in there, so maybe it eventually got through? Which tool are you using to publish?
Having said that, can-i-deploy also has retries built in. So maybe it just hit the limit when can-i-deploy ran.
if your build doesn’t fail but the publish wasn’t successful, you might get strange results further down the deployment pipeline that might be hard to reason about
This is one of the reasons why a git sha should be used in the can-i-deploy commands, and not “--latest”
s
Actually the
can-I-deploy
stage also failed in the consumer
CI CD
but the
publish contract stage
did not.
b
right
which language was the publish in?
language/tool
s
I used JavaScript
b
can you share the code?
s
Copy code
const { Publisher } = require('@pact-foundation/pact');
const path = require('path');
const childProcess = require('child_process');

const exec = (command) => childProcess.execSync(command).toString().trim();

const gitSha = process.env.GIT_COMMIT || exec('git rev-parse HEAD');
const branch =
  process.env.GIT_BRANCH || exec('git rev-parse --abbrev-ref HEAD');

const opts = {
  pactFilesOrDirs: [path.resolve(process.cwd(), 'pact/pacts')],
  pactBroker: process.env.PACT_BROKER_URL,
  pactBrokerUsername: process.env.PACT_BROKER_BASIC_CREDENTIALS_USR,
  pactBrokerPassword: process.env.PACT_BROKER_BASIC_CREDENTIALS_PSW,
  consumerVersion: gitSha,
  tags: [branch],
};

const publisher = new Publisher(opts)
  .publishPacts()
  .then(() => {
    console.log('Pact contract publishing complete!');
    console.log(
      `Head over to ${process.env.PACT_BROKER_URL} to see your published contracts.`
    );
  })
  .catch((e) => {
    console.log('Pact contract publishing failed: ', e);
  });
t
That script won't fail your build pipeline if the publish fails
b
Copy code
.catch((e) => {
    console.log('Pact contract publishing failed: ', e);
  });
💯 1
t
(Unless your build pipeline is reading the log, I suppose)
b
By the way, we recommend people use the pact-cli to publish pacts now, rather than wrapping it with javascript. This is one of the reasons why!
I think there are examples in the js codebase, aren’t there Tim?
t
Possibly. We removed them at some point because it's much better to use the CLI (which is also included)
Oh, right, yes. There are examples using the CLI. They all do, I believe
Sorry, haven't woken up yet
s
So I use maven provider to publish contract to broker. Are you still recommending to use CLI for Java or other languages as well?
b
we’d rather people did, so we could stop having to support maven 😆
But I believe the maven one is still supported for now.
t
My view (although I'm not a maintainer) is that it would be best to support whatever is idiomatic in the language you're using. In node, it's idiomatic to call CLI commands, so pact-js exposes the CLI for you to use
In the JVM world, maven / gradle plugins would be idiomatic
s
Make sense!! Thank you guys