launchdarkly / ld-find-code-refs

Build tool for automatically sending feature flag code references to LaunchDarkly
https://launchdarkly.com
Other
45 stars 34 forks source link

Reference Pruning with Azure DevOps pipelines does not seem to work #316

Open bknapik-ah4r opened 1 year ago

bknapik-ah4r commented 1 year ago

I am continuing to run into a warning regarding reference pruning in a azure devops pipeline. Specifically, I get this warning:

INFO: 2023/01/13 17:44:47 coderefs.go:199: attempting to prune old code reference data from LaunchDarkly
WARNING: 2023/01/13 17:44:47 coderefs.go:202: unable to retrieve branch list from remote, skipping code reference pruning: authentication required

A snippet from my pipeline YAML is the following:

      - checkout: self
         persistCredentials: true
      - task: Bash@3
        displayName: Set Branch Name From PR
        condition: eq(variables['Build.Reason'], 'PullRequest')
        inputs:
          targetType: inline
          script: |
            FULL_SOURCE_BRANCH_NAME=$(System.PullRequest.SourceBranch)
            SOURCE_BRANCH=${FULL_SOURCE_BRANCH_NAME##*/}
            echo "Source Branch Name: $SOURCE_BRANCH"
            echo "##vso[task.setvariable variable=sourceBranchName]$SOURCE_BRANCH"
      - task: Bash@3
        displayName: Set Branch Name from source branch
        condition: ne(variables['Build.Reason'], 'PullRequest')
        inputs:
          targetType: inline
          script: |
            FULL_SOURCE_BRANCH_NAME=$(System.PullRequest.SourceBranch)
            SOURCE_BRANCH=${FULL_SOURCE_BRANCH_NAME##*/}
            echo "Source Branch Name: $(Build.SourceBranchName)"
            echo "##vso[task.setvariable variable=sourceBranchName]$(Build.SourceBranchName)"
      - task: Bash@3
        displayName: Run Launch Darkly Find Code Refs
        inputs:
          targetType: inline
          script: |
            curl -L https://github.com/launchdarkly/ld-find-code-refs/releases/download/v2.8.0/ld-find-code-refs_2.8.0_linux_amd64.tar.gz | tar xvz -C $(Agent.TempDirectory)
            $(Agent.TempDirectory)/ld-find-code-refs --debug --dir=. --accessToken=XXX --projKey=${{ parameters.launchDarklyProjectKey }} --repoName=$(Build.Repository.Name) --branch=$(sourceBranchName)

The pipeline in essence, checks out the code, figures out the branch name, then runs ld-find-code-refs on the current directory. From what I can gather it seems like ld-find-code-refs does not integrate with the git authorization in azure pipelines.

I am setting persistCredentials which gives the pipeline access to the entire repository. From the documentation: "Set to 'true' to leave the OAuth token in the Git config after the initial fetch. The default is not to leave it." We are able use persist credentials in other parts of our pipelines successfully to push tags for example.

To try and debug this process, I was looking in the code and it seems like it is looking for a .git folder. I have confirmed that the .git folder exists when running the pipeline. The .git folder has the following files/subfolders:

FETCH_HEAD
HEAD
branches
config
description
hooks
index
info
logs
objects
refs

Is there a way to have reference pruning work in azure pipelines? If not, is there some a way we can request it to be added in a future release?

Thanks

jazanne commented 1 year ago

Hi, thank you for submitting this issue. This is a known issue with branch pruning that was introduced in v2.6.1. Sorry for the inconvenience.

bknapik-ah4r commented 1 year ago

Thanks for letting me know. I changed my pipeline to 2.6.0 and that seems to work. I will continue to track this ticket and will update my pipelines to the latest when it is resolved.

bknapik-ah4r commented 4 months ago

Is there any plan to address this? I am continuing to run 2.6.0 due to the bug introduced in 2.6.1 that broke this functionality in Azure Devops.

I am looking to upgrade if possible, as I was hoping it may help with my degradation of performance in azure pipelines. See LaunchDarkly support ticket 62946 for details.

jazanne commented 4 months ago

@bknapik-ah4r at this time we don't have a planned fix for the pruning error, however you can run newer versions of the CLI with --prune=false to skip the failing step