今天,我在 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
有什么线索吗?
谢谢!
以防将来有人遇到同样的问题,我已修复它。
这是由 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