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

n9vozmp4  于 2023-09-29  发布在  Git
关注(0)|答案(1)|浏览(91)

今天,我在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

有线索吗

ryhaxcpt

ryhaxcpt1#

如果将来有人遇到同样的问题,我会解决它。
这是由bitbucket流水线的“性能”限制引起的,它只考虑最后50次提交。所以,如果你的标签(或你正在寻找的其他任何东西)超过50次提交,它将不会找到任何东西。
要修复它,你必须添加一个命令来强制你的管道在你需要的步骤上克隆完整的repo:

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

相关问题