MR Job fails when no merge request found #14

Open
opened 2022-01-22 05:37:11 +00:00 by jon_nfc · 19 comments
jon_nfc commented 2022-01-22 05:37:11 +00:00 (Migrated from gitlab.com)

📚 Summary

If there is no merge request on the branch, the job will fail with an output of No commit found with range: 'None'

The logic in .gitlab-ci.yml needs to be fixed.

        - MR_TITLE=$($ROOT_DIR/conventional_commits/scripts/commit.py --token "$MR_ACCESS_TOKEN" --project $PROJECT_ID --title --branch $CI_COMMIT_BRANCH)
        - echo "[DEBUG] MR_TITLE[$MR_TITLE]"
        - if [ "0$MR_TITLE" == "0" ]; then echo "DEBUG No Merge Request found"; fi
        - if [ "0$MR_TITLE" != "0" ]; then cz_exit=0 && cz check --message "$MR_TITLE" > "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/$CI_JOB_NAME/cz_output.log" 2>&1 || cz_exit=$?; fi
        - if [ "0$MR_TITLE" != "0" ]; then . $ROOT_DIR/conventional_commits/scripts/cz_junit.sh > "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests/$CI_JOB_NAME-cz.junit.xml"; fi

Don't do above suggestion as there should always be an output from commit.py

## :books: Summary If there is no merge request on the branch, the job will fail with an output of `No commit found with range: 'None'` The logic in [.gitlab-ci.yml](https://gitlab.com/nofusscomputing/projects/gitlab-ci/-/blob/3548312a9f17eb056006aeaa57af00897c9585d8/conventional_commits/.gitlab-ci.yml#L58-L61) needs to be fixed. ``` yaml - MR_TITLE=$($ROOT_DIR/conventional_commits/scripts/commit.py --token "$MR_ACCESS_TOKEN" --project $PROJECT_ID --title --branch $CI_COMMIT_BRANCH) - echo "[DEBUG] MR_TITLE[$MR_TITLE]" - if [ "0$MR_TITLE" == "0" ]; then echo "DEBUG No Merge Request found"; fi - if [ "0$MR_TITLE" != "0" ]; then cz_exit=0 && cz check --message "$MR_TITLE" > "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/$CI_JOB_NAME/cz_output.log" 2>&1 || cz_exit=$?; fi - if [ "0$MR_TITLE" != "0" ]; then . $ROOT_DIR/conventional_commits/scripts/cz_junit.sh > "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests/$CI_JOB_NAME-cz.junit.xml"; fi ``` Don't do above suggestion as there should always be an output from commit.py ### :link: References - [job failure log](https://gitlab.com/nofusscomputing/infrastructure/website/-/jobs/2004048423)
jon_nfc commented 2022-01-22 05:37:28 +00:00 (Migrated from gitlab.com)

changed the description

changed the description
jon_nfc commented 2022-01-22 05:38:35 +00:00 (Migrated from gitlab.com)

marked this issue as related to nofusscomputing/infrastructure/website#3

marked this issue as related to nofusscomputing/infrastructure/website#3
jon_nfc commented 2022-01-22 05:38:36 +00:00 (Migrated from gitlab.com)

marked this issue as related to nofusscomputing/infrastructure/website#5

marked this issue as related to nofusscomputing/infrastructure/website#5
nfc_bot commented 2022-01-22 15:03:02 +00:00 (Migrated from gitlab.com)

mentioned in issue nofusscomputing/ops#44

mentioned in issue nofusscomputing/ops#44
jon_nfc commented 2022-01-24 08:00:50 +00:00 (Migrated from gitlab.com)

Discovered to day in job https://gitlab.com/nofusscomputing/projects/gitlab-ci/-/jobs/2006748060 that it reported no merge request. Considering that the failed job in the OP is v0.5.0 there were no changes.

This job was in the nfc/gitlab-ci repo.

Discovered to day in job https://gitlab.com/nofusscomputing/projects/gitlab-ci/-/jobs/2006748060 that it reported no merge request. Considering that the failed job in the OP is v0.5.0 there were no changes. This job was in the nfc/gitlab-ci repo.
jon_nfc commented 2022-01-24 08:14:47 +00:00 (Migrated from gitlab.com)

Adjust so that all code paths are followed and in a known state

Lines 46-70

merge_requests = ""

try:

  if os.environ['CI_JOB_TOKEN'] is not None:

    headers = {'JOB_TOKEN': os.environ['CI_JOB_TOKEN']}

  if os.environ['CI_JOB_TOKEN'] == ci_job_token:

    headers = {'JOB_TOKEN': os.environ['CI_JOB_TOKEN']}

  merge_requests = requests.get(url, headers=headers, data='')
  merge_requests = merge_requests.json()
  
except:
+   merge_requests = ""
    pass

+try_supplied_token = false
+
if not isinstance(merge_requests, list):
+    try_supplied_token = true
+
+if isinstance(merge_requests, list):
+    if len(merge_requests) == 0:   
+        try_supplied_token = true
+
+if try_supplied_token:
  headers = {'PRIVATE-TOKEN': ci_job_token}

  merge_requests = requests.get(url, headers=headers, data='')

  merge_requests = merge_requests.json()

Adjust so that all code paths are followed and in a known state [Lines 46-70](https://gitlab.com/nofusscomputing/projects/gitlab-ci/-/blob/46cc1fbb6a878e485af39e679b5184a9912c2e7f/conventional_commits/scripts/commit.py#L46-L70) ``` patch merge_requests = "" try: if os.environ['CI_JOB_TOKEN'] is not None: headers = {'JOB_TOKEN': os.environ['CI_JOB_TOKEN']} if os.environ['CI_JOB_TOKEN'] == ci_job_token: headers = {'JOB_TOKEN': os.environ['CI_JOB_TOKEN']} merge_requests = requests.get(url, headers=headers, data='') merge_requests = merge_requests.json() except: + merge_requests = "" pass +try_supplied_token = false + if not isinstance(merge_requests, list): + try_supplied_token = true + +if isinstance(merge_requests, list): + if len(merge_requests) == 0: + try_supplied_token = true + +if try_supplied_token: headers = {'PRIVATE-TOKEN': ci_job_token} merge_requests = requests.get(url, headers=headers, data='') merge_requests = merge_requests.json() ```
jon_nfc commented 2022-01-24 08:14:47 +00:00 (Migrated from gitlab.com)

added 25m of time spent

added 25m of time spent
jon_nfc commented 2022-01-24 08:23:06 +00:00 (Migrated from gitlab.com)

added 10m of time spent

added 10m of time spent
jon_nfc commented 2022-01-24 08:27:18 +00:00 (Migrated from gitlab.com)

Check if the http request returns an unauthorized for the ci token

Check if the http request returns an unauthorized for the ci token
jon_nfc commented 2022-01-24 08:27:29 +00:00 (Migrated from gitlab.com)

added 5m of time spent

added 5m of time spent
jon_nfc commented 2022-01-24 08:28:27 +00:00 (Migrated from gitlab.com)

changed the description

changed the description
jon_nfc commented 2022-01-25 08:48:34 +00:00 (Migrated from gitlab.com)

mentioned in merge request !17

mentioned in merge request !17
nfc_bot commented 2022-08-26 01:12:53 +00:00 (Migrated from gitlab.com)

mentioned in issue nofusscomputing/ops#55

mentioned in issue nofusscomputing/ops#55
nfc_bot commented 2022-09-26 00:31:13 +00:00 (Migrated from gitlab.com)

mentioned in issue nofusscomputing/ops#67

mentioned in issue nofusscomputing/ops#67
jon_nfc commented 2022-10-14 00:12:04 +00:00 (Migrated from gitlab.com)

MR Job Fails when MR title returns blank

See https://gitlab.com/jon_nfc/website/-/jobs/2945668866 for Success, previous commit

See https://gitlab.com/jon_nfc/arduino-library/-/jobs/3170876243 for Failure, on next commit

CC: @jasonpage.tas, This is why the library job is failing. I'll more than likely, work on this issue to check for empty MR title, and pass if true, so that way we con get success for our jobs.

# MR Job Fails when MR title returns blank See https://gitlab.com/jon_nfc/website/-/jobs/2945668866 for Success, previous commit See https://gitlab.com/jon_nfc/arduino-library/-/jobs/3170876243 for Failure, on next commit CC: @jasonpage.tas, This is why the library job is failing. I'll more than likely, work on this issue to check for empty MR title, and pass if true, so that way we con get success for our jobs.
jon_nfc commented 2022-10-14 00:12:04 +00:00 (Migrated from gitlab.com)

added 30m of time spent

added 30m of time spent
jon_nfc commented 2022-10-14 00:19:32 +00:00 (Migrated from gitlab.com)

On further investigation, it was because the forked repo didn't have the MR_ACCESS_TOKEN variable set to give access to a private project.

On further investigation, it was because the forked repo didn't have the `MR_ACCESS_TOKEN` variable set to give access to a private project. - See next job on MR after setting access token variable: https://gitlab.com/jon_nfc/arduino-library/-/jobs/3171494909
jon_nfc commented 2022-10-14 00:19:32 +00:00 (Migrated from gitlab.com)

added 7m of time spent

added 7m of time spent
jon_nfc commented 2024-02-22 12:58:37 +00:00 (Migrated from gitlab.com)

to be confirmed if still an issue

to be confirmed if still an issue
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: infrastructure/gitlab-ci#14
No description provided.