Hi all,
For one of our node app repos, we have automatic version bumping when pull requests are merged to master. In the pipeline, a task runs which increments the patch number in package.json and creates a git tag with the new version number. The updated package.json is then committed and pushed directly on master by the pipeline with a [skip-ci] prefix on the commit message to prevent an infinite loop of builds.
This works great, however there is one nitpick and I'm wondering if a workaround exists. Because the new version number is committed with [skip-ci], Bitbucket is not detecting the build status from the original merge. Here's a visual example of what I mean:
This causes the repo's Overview to display a "no pipeline has run for the head of master" message to be displayed:
In other repos which do not have this version update, a build status is displayed which is what I would expect:
A build status icon is also missing from repo lists when the version is updated like this:
Is there a way to 'pass along' the build status when committing the updated version number in package.json, or maybe a different workflow I could use here? If not, is there anything on the roadmap to accommodate a situation like this?
Thank you,
Steve
For anyone that finds this question, here is the solution we have in place. It's still not ideal, as the "no pipeline has run for the head of master" message is still displayed, but it at least passes on the build result icon and URL to the new commit.
This requires a custom Docker image with the following packages installed: curl, git, jq2
Additionally, an admin username and password need to be set as environment variables. We have these set as secret environment variables in the Team settings so that it doesn't need to be set for each individual repo. In this script, these are $PIPELINE_USERNAME and $PIPELINE_PASSWORD. The other environment variables used are built-in when using Pipelines.
#!/bin/bash
API_BASE="https://api.bitbucket.org/2.0/repositories"
API_AUTH="--user $PIPELINE_USERNAME:$PIPELINE_PASSWORD"
API_URL="$API_BASE/$BITBUCKET_REPO_OWNER/$BITBUCKET_REPO_SLUG"
## get status from last pipeline step
PIPELINE_URL=`curl $API_AUTH $API_URL/commit/$BITBUCKET_COMMIT/statuses \
| jq2 '$.values[0].url'`
PIPELINE_ID=`echo $PIPELINE_URL | sed -E 's/.+\/([[:digit:]]+)/\1/g'`
PIPELINE_RESULT=`curl $API_AUTH $API_URL/pipelines/$PIPELINE_ID/steps/ \
| jq2 '$.values[0].state.result.name'`
## format pipeline build status
read -d '' BUILD_STATUS <<- EOF
{
\"key\": \"STATUS\",
\"state\": \"$PIPELINE_RESULT\",
\"url\": \"$PIPELINE_URL\"
}
EOF
## pass along status to new version bump commit
git pull
NEW_COMMIT=`git rev-parse HEAD`
curl $API_AUTH $API_URL/commit/$NEW_COMMIT/statuses/build \
-H "Content-Type: application/json" \
-d "$BUILD_STATUS" \
-X POST
This script is added to the custom Docker image and executed from bitbucket-pipelines.yml in a final step after the build is complete and the version has been bumped.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.