https://infracost.io logo
#help
Title
# help
a

acoustic-actor-19289

08/01/2023, 5:13 AM
Hi, i m using infracost in my ci/cd in gitlab but the job is getting error
warning: Could not find remote branch  to clone.
fatal: Remote branch  not found in upstream origin
When i echo
CI_MERGE_REQUEST_TARGET_BRANCH_NAME
i m not getting any value
$ echo CI_MERGE_REQUEST_TARGET_BRANCH_NAME=${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}
CI_MERGE_REQUEST_TARGET_BRANCH_NAME=
using same code as mentioned in https://gitlab.com/infracost/infracost-gitlab-ci
r

red-toothbrush-65619

08/01/2023, 10:34 AM
a

acoustic-actor-19289

08/01/2023, 10:34 AM
yeah, i saw that
r

red-toothbrush-65619

08/01/2023, 10:36 AM
Found this to be the issue so create this code
Copy code
- echo "OPEN MERGE REQUEST ID:" "${CI_OPEN_MERGE_REQUESTS##*\!}"
     - |
        if [ -n "${CI_OPEN_MERGE_REQUESTS##*\!}" ]; then
          export INFRACOST_VCS_PULL_REQUEST_TITLE=$(curl --silent --request GET --header "PRIVATE-TOKEN:${AUTOMATION_ADMIN_TOKEN}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/merge_requests/${CI_OPEN_MERGE_REQUESTS##*\!}" | jq -r '.title')
          export INFRACOST_VCS_PULL_REQUEST_URL="${CI_PROJECT_URL}/-/merge_requests/${CI_OPEN_MERGE_REQUESTS##*\!}"
          echo "INFRACOST_VCS_PULL_REQUEST_TITLE:" "$INFRACOST_VCS_PULL_REQUEST_TITLE"
          echo "INFRACOST_VCS_PULL_REQUEST_URL:" "$INFRACOST_VCS_PULL_REQUEST_URL"
        fi
To get the details need
a

acoustic-actor-19289

08/01/2023, 10:37 AM
sure, let me try
r

red-toothbrush-65619

08/01/2023, 10:42 AM
FYI "CI_JOB_TOKEN" is the nornal token for API calls in a pipeline
Copy code
${AUTOMATION_ADMIN_TOKEN}
Is are Own thing 🙂
b

busy-agent-35515

08/01/2023, 12:09 PM
@acoustic-actor-19289 Hello! Sorry, have to ask for context: the pipeline is run on the PR open/change event, right? Also, are you using the gitlab.com or a self-managed instance?
a

acoustic-actor-19289

08/01/2023, 12:10 PM
Yes, pipeline will run after MR and we are using gitlab runners
b

busy-agent-35515

08/01/2023, 12:14 PM
This is strange, the env var is controlled by GitLab 🤔
Is it possible to post your pipeline here?
a

acoustic-actor-19289

08/01/2023, 12:14 PM
Yes
Due to security reasons, no
b

busy-agent-35515

08/01/2023, 12:17 PM
Can you at least post the trigger rules?
a

acoustic-actor-19289

08/07/2023, 12:22 PM
This has been fixed
b

busy-agent-35515

08/07/2023, 12:22 PM
Glad to hear it! Can you share what was the issue?
a

acoustic-actor-19289

08/07/2023, 12:29 PM
I missed to use the rules
Copy code
rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
b

busy-agent-35515

08/07/2023, 12:29 PM
Thanks 👍
a

acoustic-actor-19289

08/07/2023, 12:31 PM
Also was getting Error while commenting on gitlab , Gitlab token variable was added as Protected
Thanks @busy-agent-35515 for your support
b

busy-agent-35515

08/07/2023, 1:27 PM
Sure thing, but you managed to fix everything yourself. Good job! 🙂 Does Infracost work for you as you expected?
a

acoustic-actor-19289

08/07/2023, 1:29 PM
yes,
31 Views