Environment variable for last successful commit

Issue #13805 open
Evgenii Sokolov
created an issue

Would be nice to have COMMIT_RANGE as a env- variable, similar to https://docs.travis-ci.com/user/environment-variables/ - TRAVIS_COMMIT_RANGE

We want to check coding style for changes, but it is make no sense to check all files, and we want to check only changes between in this build.

It would be nice if range will be started from last "successfull build".

Comments (2)

  1. Matt Ryall staff

    That's a good idea, thanks for the suggestion. It seems very useful, but unfortunately it will probably be a while before we have capacity to add this to Pipelines, given the other competing feature requests.

    For now, I'd suggest you probably want to come up with a script to do this yourself. Here's how I'd think about doing it:

    • use git log --format=%h -n 10 to get a list of the recent commit hashes
    • loop over these and use the Bitbucket REST API to get the build status and check for "state": "SUCCESSFUL" in the response.

    Here's a shell script snippet that you might be able to adapt:

    for COMMIT in `git log --format=%h -n 10`; do
        curl --user '$BB_USER:$BB_PASS' 'https://api.bitbucket.org/2.0/repositories/$BITBUCKET_REPO_OWNER/$BITBUCKET_REPO_SLUG/commit/$COMMIT/statuses/'` | \
            grep -q 'SUCCESSFUL' && \
            echo "$COMMIT was successful"
    done
    

    You can create a read-only app password to configure the $BB_USER and $BB_PASS environment variables in your pipeline.

  2. Log in to comment