Apologies for cross-posting this with <#C9VBGLUM9|...
# pact-broker
a
Apologies for cross-posting this with #C9VBGLUM9 but I'm not sure whether its a client or server thing (or both): I'm publishing contracts from a Nodejs consumer running
@pact-foundation/pact: 12.5.2
and using the
--auto-detect-version-properties
switch when using the pact-broker publish command. This is running in a BitBucket Cloud pipeline. The docs say this flag:
Copy code
Automatically detect the repository commit, branch and build URL from known CI environment variables or git CLI
When I look in the
branch_versions
table I can see a new row with the expected branch name and underlying version number, but: • The associated row of
versions
has blank
build_url
and
repository_ref
columns (I'm assuming the former should contain the "build URL" described above • I'm not sure where the "repository commit" alluded to above would crop up in the pact broker DB, so I'm not sure where to check for that. Should I expect repository commit and build URL to be recorded in the DB somewhere? If they should be, any advice for how to track down why they are not appearing?
y
Hey Alan, It should pick up the following env vars https://github.com/pact-foundation/pact_broker-client/blob/cb2e41145d320190642349c2790cb6acb35eab4c/lib/pact_broker/client/git.rb#L5 https://github.com/pact-foundation/pact_broker-client/blob/cb2e41145d320190642349c2790cb6acb35eab4c/lib/pact_broker/client/git.rb#L31 It may be that these have changed in BK so I would probably start with checking if they are set What output do you see when publishing with the pact-broker publish command? You can also running it in verbose for a bit of extra logging.
a
Thanks @Yousaf Nabi (pactflow.io) - I will check those envVars in my pipeline. I do have
--verbose
set on the call to publish - is there anything in particular I should be looking for in there?
y
Created GoAdminService version bf65b7406bec6dd9a15569ec1441649ea19a51c0 with branch master
You should see something like the above, with version <version> being the commit (if it has been picked up). it actually wont let you publish without a commit version
so just wondering if you have the correct commit, we can then check the build url
a
It reports this:
Created foo version 285bd2d-featurepact-use-branch-not-tag+285bd2d with branch feature/pact-use-branch-not-tag and tags feature/pact-use-branch-not-tag
The version is calculated using
npx absolute-version
, and the only slight oddity is the removal of the
/
character present in the branch from the version.
y
okay, so the removal of the / might be an absolute-version thing, as i can publish with a version foo/bar. i assume the short hash, corresponds with the start of your git commit? if you do auto detect version properties and then the consumer app version, the user provided version takes precendence
a
Yes the short hash (courtesy of absolute-version) is from the BB commit
Pretty sure the removal of
/
is an ab-ver thing too.
This is the whole cmdline:
Copy code
pact-broker publish ./pacts --consumer-app-version=<ab-ver> --auto-detect-version-properties --tag-with-git-branch --verbose --broker-base-url=<broker-url>
where
<ab-ver>
is the output
285bd2d-featurepact-use-branch-not-tag+285bd2d
from absolute-version.
fyi - just dumping out the env Var info in the pipeline this time Firstly, these are the variables that BB reports that it has set:
Copy code
BITBUCKET_BRANCH
    BITBUCKET_BUILD_NUMBER
    BITBUCKET_CLONE_DIR
    BITBUCKET_COMMIT
    BITBUCKET_GIT_HTTP_ORIGIN
    BITBUCKET_GIT_SSH_ORIGIN
    BITBUCKET_PIPELINE_UUID
    BITBUCKET_PROJECT_KEY
    BITBUCKET_PROJECT_UUID
    BITBUCKET_REPO_FULL_NAME
    BITBUCKET_REPO_IS_PRIVATE
    BITBUCKET_REPO_OWNER
    BITBUCKET_REPO_OWNER_UUID
    BITBUCKET_REPO_SLUG
    BITBUCKET_REPO_UUID
    BITBUCKET_SSH_KEY_FILE
    BITBUCKET_STEP_RUN_NUMBER
    BITBUCKET_STEP_TRIGGERER_UUID
    BITBUCKET_STEP_UUID
    BITBUCKET_WORKSPACE
Of the above I think only
BITBUCKET_BRANCH
and
BITBUCKET_COMMIT
appear in that list of envVars you sent me; in particular there's nothing to match anything in the
BUILD_URL_ENV_VAR_NAMES
list.
y
mmm yeah, sorry I mis-read as buildkite facepalm , noted the same that actually that list of env vars bb provides doesn't provide one for a url to the job
a
I just see:
Copy code
BITBUCKET_BRANCH = feature/pact-use-branch-not-tag
BITBUCKET_COMMIT = 91b019b1b56126b3af0925f22eb30f3b4f55b79c
y
I know circleci was the same as I had to create the url, from a project id env var
(for a slack reporter project I have)
a
Ah that's interesting - so I could just set
BUILD_URL
from some of the available bits as outlined in the s/o above. I'll give that a try - many thanks for your help!
y
pleasure my friend, if that works, we could probably add that into the pact broker client, although it will break at some point as the ci provider will invariably change their api.
šŸ‘ 1
a
Just to confirm, setting the envVar
BUILD_URL
to
<https://bitbucket.org/${BITBUCKET_REPO_FULL_NAME}/pipelines/results/${BITBUCKET_BUILD_NUMBER}>
prior to calling publish from the BitBucket pipeline results in the `versions.build_url`being populated in the database,
šŸ‘ 1