-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstep-set-tag-output.yml
60 lines (58 loc) · 2 KB
/
step-set-tag-output.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Version 1.0.0
# Maintainer: Kamil Piotrowski
# Description: This template can be used to retrieve and validate Git release tag.
# Parameters:
# validationRegexp: The regexp used to validate the Git deployment tag. By
# default it would match vX.Y.Z which is inspired by the
# semantic versioning (see: https://semver.org/).
# failOnNotFound: Whether to fail should no Git tag can be found,
# otherwise lack of deployment tag will not be
# treated as a failure.
# displayName: What to show in the pipeline output when the stage
# runs. By default it would be "Get Git release tag".
#
# You can override above default settings.
#
# Usage:
#
# - job: 'ValidateTag'
# steps:
# - template: 'templates/step-set-tag-output.yml'
# displayName: 'Validate deployment tag'
# - job:
# dependsOn:
# - 'ValidateTag'
# variables:
# deploymentTag: $[ dependencies.ValidateTag.outputs['GetGitTag.VERSION_TAG'] ]
# steps:
# - script: |
# echo $(deploymentTag)
parameters:
- name: 'validationRegexp'
type: 'string'
default: 'v[0-9]+(.[0-9]+){1,3}$'
- name: 'failOnNotFound'
type: 'boolean'
default: false
- name: 'displayName'
type: 'string'
default: 'Get Git release tag'
steps:
- script: |
VERSION_TAG="$( echo $(Build.SourceBranch) | sed -e 's#refs/tags/##')"
if [[ -z "$VERSION_TAG" ]]; then
printf "\n***\nRelease tag not found. Deploy will be skipped.\n***\n"
case "${{ parameters.failOnNotFound }}" in
true|True) exit 1 ;;
*) exit 0 ;;
esac
fi
if [[ "$VERSION_TAG" =~ ${{ parameters.validationRegexp }} ]]; then
echo "Release tag: $VERSION_TAG"
else
printf "\n***\nValid tag not found. Invalid tag: ${VERSION_TAG}\n***\n"
exit 1
fi
echo "##vso[task.setvariable variable=VERSION_TAG;isOutput=true]$VERSION_TAG"
name: 'GetGitTag'
displayName: '${{ parameters.displayName }}'