https://infracost.io logo
Title
s

silly-laptop-9121

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
l

little-author-61621

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

silly-laptop-9121

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
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
l

little-author-61621

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

silly-laptop-9121

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

little-author-61621

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.
s

silly-laptop-9121

08/26/2022, 9:19 AM
hi i found the issue with the API key, it is also a bug on the site
what it copies though is the key with this prepended
export INFRACOST_API_KEY=
sorry to be a pain, now i get the following error running the step:
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
l

little-author-61621

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/
s

silly-laptop-9121

08/26/2022, 9:50 AM
will do thanks
l

little-author-61621

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.
Let me know how if the curls help with debugging the token issue
s

silly-laptop-9121

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
so i am not sure what to put in the mytoken bit
is it an app password?
ok that did it, so in cloud you need to create an app password and use that instead of
$BITBUCKET_TOKEN
hope that helps
l

little-author-61621

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

silly-laptop-9121

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

little-author-61621

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

silly-laptop-9121

08/26/2022, 10:38 AM
yes so <username>:$APP_PASSWORD
l

little-author-61621

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