I'm currently using Gitlab CI/CD combined with Fastlane on our build machine to perform nightly builds of an iOS app, and push those builds to TestFlight on completion. So far, so good. However, I've been asked to generate a change log of the new commits that have gone into each night's build.

Is it possible to get not just the CI_COMMIT_SHA of the current pipeline run, but also the SHA of the previous commit that the pipeline last ran for? That way, I could generate a change log of what's new in the current pipeline run? After searching the docs on Gitlab.com, I'm coming up empty so far.

As part of the pipeline, we also generate a build manifest that includes the current commit SHAs used for the build, and save that as an artifact. So, if it was possible to download the most recent artifacts, I could also maybe just look at that manifest, but again, I'm not seeing a way to do that either.

  • Won't you have pipeline runs between the nightly builds ? The easier way seems to commit back the repo with a last_night_build file containing the current sha after computing the change log from it. – Tensibai Feb 20 at 8:53

Note: the answer is rather speculative, based on docs only, I didn't actually use GitLab pipelines yet.

You may be able to use the Pipelines API. More specifically you could get a pipeline's variables:

Get variables of a pipeline

GET /projects/:id/pipelines/:pipeline_id/variables

Attribute Type            Required    Description
id            integer/string  yes         The ID or URL-encoded path of the project owned by the authenticated user
pipeline_id   integer         yes         The ID of a pipeline

Example of response

    "key": "RUN_NIGHTLY_BUILD",
    "variable_type": "env_var",
    "value": "true"
    "key": "foo",
    "value": "bar"

I'm suspecting that in the response you'd find the variables shown in a pipeline creation response example, which include these which could be of interest to you:

  "id": 61,
  "sha": "384c444e840a515b23f21915ee5766b87068a70d",

  "before_sha": "0000000000000000000000000000000000000000",

I'm uncertain if the before_sha for the current pipeline is what you're looking for, if not you'd just get the sha for the previous pipeline ID, which you could derive from the current pipeline ID (via the CI_PIPELINE_ID environment variable, see Predefined environment variables). I'm assuming that the pipeline IDs are consecutive.

| improve this answer | |
  • CI_PIPELINE_ID is global to the instance and not specific to a project, CI_PIPELINE_IID would be scoped to the project but this doesn't guarantee the previous pipeline was a nightly build – Tensibai Feb 20 at 8:51
  • To complement what I said above, the approach could be ok that said by requesting the API to find the last nightly build pipeline, but it depends on how it is launched. – Tensibai Feb 20 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.