- Can post comment on BitBucket PR
- Can update PR comment
- Does not comment when no changes in infrastructure is detected
- Is integrated with infracost official ci scripts
I have no idea when I will tackle the open points.
The script infracost.sh takes 1 argument, the path for infracost. It generates the files infracost_breakdown.html (contains infracost breakdown in html format) and output.txt (contains diff in markdown format for PR comment).
The script post_to_bitbucket.sh takes 1 argument, the name of the current branch. It posts a new or updates an existing comment to the PR, if it exists. Also the following environment variables must be set:
BB_ADDRESSThe URL of the bitbucket instance (eg.https://bitbucket.example.comorhttps://example.com:8008/bitbucket)BB_PROJECTThe current project (not tested with the personal space)BB_REPOSITORYThe repository inside the projectBB_USERUser used to authenticate with (must have "REPO_READ" permissions)BB_PASSWORDDo I have to explain this?
terraform plan -no-color -out=tf.plan
terraform show -json tf.plan > plan.json
./infracost.sh plan.json
withEnv(["BB_ADDRESS=https://bitbucket.example.com", "BB_PROJECT=test", "BB_REPOSITORY=infracost-demo"]) {
withCredentials([usernamePassword(credentialsId: "bitbucket_creads", passwordVariable: 'BB_PASSWORD', usernameVariable: 'BB_USER')]) {
sh("./post_to_bitbucket.sh ${current_branch}")
}
}