Surface n most recent commits in Bitrise job

Is there a way to expose more than just the most recent commit when a bitrise job executes? For example, I’d like to expose all of the commits since the last job was run, rather than just the commit that triggered the job.

What do you mean by last? On the same branch or globally? Only finished builds or running ones too?

On the same branch. So if I make five commits locally, push to remote, then a build is triggered, am I able to see all 5 recent commits? Or is there a way that I can just always see the last n number of commits on a branch?

1 Like

In general, with git:

git log  --pretty=oneline | head -n 5

or:

git log -5

You can get this in a Script step, and expose it as an env var with any key you like, e.g.:

#!/bin/bash
set -ex

# get the info
last_five_oneliner="$(git log -5 --pretty=oneline)"

# share it as an env var
envman add --key MY_ENV_KEY --value "$last_five_oneliner"

The output of git log -5 --pretty=oneliner looks like this:

$ git log -5 --pretty=oneline

bd943b403cac75c4164a34fe8786b9a86897ab2c v0.9.6.
cac4e12b72d75a074808d2a1d3c34bf8e18851fd bug when immediately editin step after adding it - fixed
2ac992ba9341971d3c2b9ace8ae00feabc6866ad font set to open sans
e91b8dc95c03b43e3fba440ec18a919ce30fbd00 readme updated
070fc68e5ba1ec5cf476dbcd217412b79162d2bf changelog updated

A quick example bitrise.yml which runs this as a Script step, and then prints the value in another one:

format_version: 2
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
trigger_map:
- push_branch: '*'
  workflow: primary
- pull_request_source_branch: '*'
  workflow: primary
workflows:
  primary:
    steps:
    - script@1.1.3:
        title: Read & Expose git info
        inputs:
        - content: |-
            #!/bin/bash
            set -ex

            # get the info
            last_five_oneliner="$(git log -5 --pretty=oneline)"

            # share it as an env var
            envman add --key MY_ENV_KEY --value "$last_five_oneliner"
    - script@1.1.3:
        title: Print exposed value
        inputs:
        - content: |-
            #!/bin/bash
            set -e

            echo "MY_ENV_KEY: $MY_ENV_KEY"

If you have any questions just let me know!

Thanks! This worked like a charm!

1 Like