Title
#general
p

Paul Bradbury

08/26/2022, 8:21 AM
Just trying to install infracost in a bitbucket pipeline, but I am getting an error when trying to clone the repo, has anyone done this successfully, I have an ssh key on the repo as its private and have the public key for that as an access key
Alistair (Infracost)

Alistair (Infracost)

08/26/2022, 8:34 AM
Hi Paul, what error are you seeing? And do you have an example of the pipeline you have?
p

Paul Bradbury

08/26/2022, 8:51 AM
The error is
+ git clone $BITBUCKET_GIT_HTTP_ORIGIN --branch=$BITBUCKET_PR_DESTINATION_BRANCH --single-branch /tmp/base
Cloning into '/tmp/base'...
fatal: could not read Username for '<https://bitbucket.org>': No such device or address
8:52 AM
The pipeline is basically the one in the documentation
pull-requests:
"**":
- step:
name: Run infracost
image: infracost/infracost:ci-0.10
script:
- git clone $BITBUCKET_GIT_HTTP_ORIGIN --branch=$BITBUCKET_PR_DESTINATION_BRANCH --single-branch /tmp/base
#- |
#  mkdir -p ~/.ssh
# eval ssh-agent -s`` _`# echo "$GIT_SSH_KEY" | tr -d '\r' | ssh-add -`_ _`# ssh-keyscan bitbucket.org
~/.ssh/known_hosts`_
`# Generate Infracost JSON file as the baseline, add any required sub-directories to path, e.g.
/tmp/base/PATH/TO/TERRAFORM/CODE
.`
- _|_
infracost breakdown --path=/tmp/base/ \
--format=json \
--out-file=infracost-base.json
# Generate an Infracost diff and save it to a JSON file.
- _|_
infracost diff --path=./ \
--compare-to=infracost-base.json \
--format=json \
--out-file=infracost.json
# Posts a comment to the PR.
- _|_
INFRACOST_ENABLE_CLOUD=true infracost comment bitbucket --path=infracost.json \
--repo=$BITBUCKET_WORKSPACE/$BITBUCKET_REPO_SLUG \
--pull-request=$BITBUCKET_PR_ID \
--bitbucket-token=radiateb2b3:$BITBUCKET_TOKEN \
--behavior=update
Alistair (Infracost)

Alistair (Infracost)

08/26/2022, 8:54 AM
hmm, can you try it with
- git clone $BITBUCKET_GIT_SSH_ORIGIN...
p

Paul Bradbury

08/26/2022, 8:58 AM
that did it great thanks
8:59 AM
its just telling me my api key is wrong now so need to double check that
Alistair (Infracost)

Alistair (Infracost)

08/26/2022, 8:59 AM
Awesome, thanks for reporting. I'll try it out with a few other things and see how we update the docs for it.
p

Paul Bradbury

08/26/2022, 9:19 AM
hi i found the issue with the API key, it is also a bug on the site
9:20 AM
what it copies though is the key with this prepended
export INFRACOST_API_KEY=
9:23 AM
sorry to be a pain, now i get the following error running the step:
9:23 AM
time="2022-08-26T09:21:30Z" level=info msg="Estimate uploaded to organization 'paul' in Infracost Cloud"
time="2022-08-26T09:21:30Z" level=info msg="Finding matching comments for tag generated by Infracost"
Error: The pull request comment was generated successfully but could not be posted:
Error getting comments: 401 Unauthorized
Alistair (Infracost)

Alistair (Infracost)

08/26/2022, 9:49 AM
Looks like a token issue of some sort. Can you try the curl calls from the Troubleshooting section here: https://bitbucket.org/infracost/infracost-bitbucket-pipeline/src/master/
p

Paul Bradbury

08/26/2022, 9:50 AM
will do thanks
Alistair (Infracost)

Alistair (Infracost)

08/26/2022, 10:11 AM
what it copies though is the key with this prepended
export INFRACOST_API_KEY=
Ah interesting, yeah I think that’s so it works locally, but that doesn’t make sense for CI/CD. I’ll chat to the team and see if we want to change this.
10:11 AM
Let me know how if the curls help with debugging the token issue
p

Paul Bradbury

08/26/2022, 10:26 AM
ok struggling a bit with the token, as far as i can tell you only get http access tokens for the server version of bitbucket not the cloud version
10:27 AM
so i am not sure what to put in the mytoken bit
10:27 AM
is it an app password?
10:33 AM
ok that did it, so in cloud you need to create an app password and use that instead of
$BITBUCKET_TOKEN
10:33 AM
hope that helps
Alistair (Infracost)

Alistair (Infracost)

08/26/2022, 10:34 AM
Ah yeah, in Bitbucket Cloud it has to be a user password or app password.
10:36 AM
Is that working in the pipeline now as well?
p

Paul Bradbury

08/26/2022, 10:36 AM
it is thanks
10:36 AM
i created a local repo variable and oput the app password in there
10:37 AM
thanks for the help
Alistair (Infracost)

Alistair (Infracost)

08/26/2022, 10:37 AM
For the
BITBUCKET_TOKEN
did you still have to prepend it with
<username>:…
?
p

Paul Bradbury

08/26/2022, 10:38 AM
yes so <username>😒APP_PASSWORD
Alistair (Infracost)

Alistair (Infracost)

08/26/2022, 10:38 AM
Great thanks!