Hi, i m using infracost in my ci/cd in gitlab but ...
# help
a
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
a
yeah, i saw that
r
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
sure, let me try
r
FYI "CI_JOB_TOKEN" is the nornal token for API calls in a pipeline
Copy code
${AUTOMATION_ADMIN_TOKEN}
Is are Own thing 🙂
b
@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
Yes, pipeline will run after MR and we are using gitlab runners
b
This is strange, the env var is controlled by GitLab 🤔
Is it possible to post your pipeline here?
a
Yes
Due to security reasons, no
b
Can you at least post the trigger rules?
a
This has been fixed
b
Glad to hear it! Can you share what was the issue?
a
I missed to use the rules
Copy code
rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
b
Thanks 👍
a
Also was getting Error while commenting on gitlab , Gitlab token variable was added as Protected
Thanks @busy-agent-35515 for your support
b
Sure thing, but you managed to fix everything yourself. Good job! 🙂 Does Infracost work for you as you expected?
a
yes,