无法从我的 bitbucket 管道脚本运行任何 git 命令

问题描述 投票:0回答:1

今天,我在 bitbucket 管道上遇到 git 命令的问题。

当尝试获取标签列表时,没有任何反应(几乎),因此,我的 $version 变量为空。

image: hashicorp/terraform

pipelines:
  custom:
    deploy-manually:
      - variables:  # List variable names under here
          - name: Environment
          - name: Action
      - step:
           name: Security Scan
           script:
             - pipe: atlassian/git-secrets-scan:0.5.1
      - step:
          name: Modify locals.tf file for $Environment
          trigger: manual
          script:
             - terraform init
             
             #Install dependancies
             - |
               echo "Install needed dependancies"    
             - apk update;
             - apk add jq;
             - apk add --no-cache curl ;
             - apk add bash;
             - apk add python3;
             - version=$(git tag --list | grep -E '^[0-9]+\.[0-9]+(\.[0-9]+)?(-[a-zA-Z0-9]+)?$' | sort -V | tail -n1)
             - |
                echo "Latest tag found: $version"
              [...]
      - step:
          name: Deploy completed
          trigger: manual
          script:
            - terraform validate

有什么线索吗?

谢谢!

git bitbucket-pipelines
1个回答
0
投票

以防将来有人遇到同样的问题,我已修复它。

这是由 bitbucket 管道的“性能”限制造成的,该管道仅考虑最后 50 次提交。 因此,如果您的标签(或您正在寻找的任何其他内容)的提交时间超过 50 次,它将找不到任何内容。

要修复它,您必须添加一个命令来强制您的管道在您需要的步骤上克隆完整的存储库:

image: hashicorp/terraform

pipelines:
  custom:
    deploy-manually:
      - variables:  # List variable names under here
          - name: Environment
          - name: Action
      - step:
           name: Security Scan
           script:
             - pipe: atlassian/git-secrets-scan:0.5.1
      - step:
          name: Modify locals.tf file for $Environment
          clone:
            depth: full
          trigger: manual
          script:
             - terraform init
             
             #Install dependancies
             - |
               echo "Install needed dependancies"    
             - apk update;
             - apk add jq;
             - apk add --no-cache curl ;
             - apk add bash;
             - apk add python3;
             - version=$(git tag --list | grep -E '^[0-9]+\.[0-9]+(\.[0-9]+)?(-[a-zA-Z0-9]+)?$' | sort -V | tail -n1)
             - |
                echo "Latest tag found: $version"
              [...]
      - step:
          name: Deploy completed
          trigger: manual
          script:
            - terraform validate

© www.soinside.com 2019 - 2024. All rights reserved.