question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

First run in Gitlab CI causes an error

See original GitHub issue

When using a boilerplate setup (I have a yeoman generator to create my novel projects), the very first CI run blows up when on Gitlab because $CI_BUILD_BEFORE_SHA is 0000000000000000000000000000000000000000. Since that is never a valid SHA in Git, it would be nice if the tool would look for that and just scan the entire branch or just skip it with a warning. (Or have a flag that lets you choose which one if it gets into that condition).

Expected Behavior

I use a boilerplate to set up my Gitlab repositories for my novels and stories. This is a semi-regular occurrence (1-3/month). Because I have it down to templates, I have commitlint in from the beginning of the chore: initial commit. However, when using it in a CI file, it fails because it is the first run of the CI.

image: dmoonfire/mfgames-writing-js:2.0.0

stages:
    - publish

publish:
    stage: publish
    only: [master]
    tags: [docker]
    script:
        - npm ci
        - npx commitlint --from=$CI_BUILD_BEFORE_SHA
        - npx semantic-release
        - npm run upload

When Gitlab CI starts, the environment variable is set to all zeros. The work-around is pretty simple, just make another change and push it up but that feels wrong because occasionally I forget that the first is always going to fail.

Current Behavior

 $ npx commitlint --from=$CI_BUILD_BEFORE_SHA
/builds/fedran/second-hand-dresses/node_modules/@commitlint/cli/lib/cli.js:114
	throw err;
	^
Error: fatal: Invalid revision range 0000000000000000000000000000000000000000..HEAD
    at DestroyableTransform._transform (/builds/fedran/second-hand-dresses/node_modules/git-raw-commits/index.js:83:30)
    at DestroyableTransform.Transform._read (/builds/fedran/second-hand-dresses/node_modules/readable-stream/lib/_stream_transform.js:184:10)

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

  • Add a new command-line option (--on-initial-run) have it either scan the entire branch (scan-branch) or ignore everything (ignore-previous).
  • Pick one of the above and make it a default.

Steps to Reproduce (for bugs)

  1. Create a new repository in Gitlab, turn on CI.
  2. Check in a single .gitlab-ci.yml (see above).
  3. Commit and push.

Context

  • Just trying to avoid a consistent error in CI without adding a lot of noise to a CI file for a one-time occurrence (per repository).

Your Environment

Executable Version
commitlint --version 7.6.1
git --version 2.20.1
node --version 8.16.1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
yangm97commented, Jul 28, 2021
2reactions
dmoonfirecommented, Jul 28, 2021

Since I’m usually creating a new Git repo (about 3/month) and commitlint is one of the first things I set up, I ended up writing a little NPM utility to do it for me.

npx commitlint-gitlab-ci -x @commitlint/config-conventional

It seems to work fairly well for me, I’ve been messing with it for a little while and haven’t had too many complaints.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting CI/CD - GitLab Docs
If a pipeline does not seem to run at all, with no error message, it may also be due to rules or only/except...
Read more >
Top 10 Most Common Errors In GitLab CI Pipelines - Medium
First, check if you have named the pipeline exactly .gitlab-ci.yml and is located at the root of your project.
Read more >
Troubleshoot GitLab Runner
Is it possible to run GitLab Runner in debug/verbose mode. From a terminal, run: ... The error is caused by the time package...
Read more >
Script command using ":" causing error in .gitlab-ci.yml execution
This very simple script is causing an error because the colons(:) in the "Content-Type: multipart/form-data" piece. Running the CI Lint in ...
Read more >
GitLab Runner: Argument List too long because of Self Signed ...
Running with gitlab-runner 13.11.0 (7f7a4bb0) on azure Lgbh_aXr ... user process caused: argument list too long ERROR: Job failed (system ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found