我创建了下面的任务,以便在使用新标签构建docker镜像时找到当前标签并传递给下一个任务。
- task: Bash@3
displayName: 'Fetch latest tag from ECR and Create Next Tag.'
inputs:
targetType: 'inline'
script: |
ecrURI=$(ecrURI)
repoName="${ecrURI##*/}"
latestECRTag=$(aws ecr describe-images --output json --repository-name ${repoName} --region $(awsDefaultRegion) --query 'sort_by(imageDetails,& imagePushedAt)[-1].imageTags[0]' | jq . --raw-output)
if [[ -z ${latestECRTag} ]];
then
latestECRTag='0.0.0'
fi
major=$(echo ${latestECRTag} |cut -d'.' -f1)
minor=$(echo ${latestECRTag} |cut -d'.' -f2)
patch=$(echo ${latestECRTag} |cut -d'.' -f3)
latestECRTag="$(expr $major + 1).${minor}.${patch}"
echo $latestECRTag
echo "##vso[task.setvariable variable=NEXT_ECR_TAG;isOutput=true]$latestECRtag"
- bash: |
echo "Started Building Docker Image with tag $latestECRTag"
docker build -t test:latest -f Dockerfile .
docker tag test:latest $(ecrURI):$(NEXT_ECR_TAG)
displayName: 'Build Docker Image with Tag.'
workingDirectory: $(System.DefaultWorkingDirectory)/configCreate/
获取和创建新标签的stptask工作正常,但当我转到下一个任务时,我基于 NEXT_ECR_TAG
它显示我是空值,其他的都是正确填充的。
有谁能帮我找到为什么我不能获取的 NEXT_ECR_TAG
在下一个任务中的价值?这可能是件傻事,但不知道是什么?
我的变量中出现了一个错别字。修正错别字后,一切都解决了。