hi im having trouble integrating infracost into az...
# help
hi im having trouble integrating infracost into azure pipelines. when running the pipeline im getting the error in below screenshot. im stuck at cloning the base branch. the pipeline uses the System.PullRequest.TargetBranchName variable is only set if the build reason is pull request. im integrating this with terraform and want i want to check out the base branch if i run the pipeline from a feature branch and not only if i create a pull request. did anyone get this to work?
@billowy-vase-97860 could something like this work?
Copy code
- bash: |
    if [ -z "$(System.PullRequest.TargetBranchName)" ]; then
      # If System.PullRequest.TargetBranchName is not set, default to 'main'
      # If it is set, use the specified target branch name
    # Clone the base branch (either the target branch of the PR or the default branch) into a temp directory.
    git clone $(Build.Repository.Uri) --branch=$TARGET_BRANCH --single-branch /tmp/base
  displayName: Checkout base branch
I think ^ would only work on the main branch, but you can switch
in that if statement so it uses the feature branch name, this page has the predefined env vars in azure pipelines in case that doesn’t work
hi ali and alistair thank you for your valuable input. what is the main reason the azure pipeline template uses System.PullRequest.TargetBranchName?. Because this wil cause a failure of your pipeline when you run the pipeline from your own feature branch. just curious!
@billowy-vase-97860 Infracost CI/CD integrations create a pull request comment with the diff of the costs and finops best practices/policies so engineers get the right info, at the right time, in their workflow. That means they only see the cost/FinOps results of the things they’re changing. When you run infracost breakdown on a feature branch, it scans all resources, hence engineers get a potentially long list, and don’t know what was there before vs what they changed. That often leads to them not being able to take action to fix things as in reality, there are usually lots of things that need changes on the branch, but they should care about the things they’re changing/adding.
I forgot to mention that the CI/CD example, also has the
task, that runs on default branch pushes and updates Infracost Cloud with the full branch scan so you can see all issues regardless of what’s being changed in PRs. That’s not to say you must follow our integrations, of course you can change them to do what’s best for your environment 🙂