Skip to content

Commit f8e3773

Browse files
authored
trigger-pipeline tag support #89 (#90)
* trigger-pipeline tag support #89
1 parent 05cafe5 commit f8e3773

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

scripts/trigger-pipeline.sh

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,28 @@ cat > /tmp/swissknife/trigger_pipeline.sh <<'EOF'
1919
export vcs_type="$1";
2020
export username="$2";
2121
export reponame="$3";
22-
export branch="$4";
23-
export params="$5";
22+
if [[ $4 == "-t" ]]; then
23+
export tag="$5";
24+
export params="$6";
25+
export body='{
26+
"tag": "'$tag'",
27+
"parameters": '"$params"'
28+
}';
29+
else
30+
export branch="$4";
31+
export params="$5";
32+
export body='{
33+
"branch": "'$branch'",
34+
"parameters": '"$params"'
35+
}';
36+
fi
2437
2538
trigger_workflow() {
2639
curl --silent -X POST \
2740
"https://circleci.com/api/v2/project/$vcs_type/$username/$reponame/pipeline?circle-token=${CIRCLE_TOKEN}" \
2841
-H 'Accept: */*' \
2942
-H 'Content-Type: application/json' \
30-
-d '{
31-
"branch": "'$branch'",
32-
"parameters": '"$params"'
33-
}'
43+
-d "${body}"
3444
}
3545
3646
trigger_workflow
@@ -44,7 +54,12 @@ chmod +x /tmp/swissknife/trigger_pipeline.sh
4454
PARAM_USER=$(printf '%s\n' "${!PARAM_USER_ENV_VAR}")
4555
PARAM_REPO=$(printf '%s\n' "${!PARAM_REPO_ENV_VAR}")
4656
PARAM_BRANCH=$(printf '%s\n' "${!PARAM_BRANCH_ENV_VAR}")
57+
PARAM_TAG=$(printf '%s\n' "${!PARAM_TAG_ENV_VAR}")
4758

4859
if [[ "$SKIP_TRIGGER" == "0" || "$SKIP_TRIGGER" == "false" ]]; then
49-
/tmp/swissknife/trigger_pipeline.sh "$VCS_TYPE" "$PARAM_USER" "$PARAM_REPO" "$PARAM_BRANCH" "$CUSTOM_PARAMS"
60+
if [[ "$PARAM_BRANCH_ENV_VAR" != "" ]]; then
61+
/tmp/swissknife/trigger_pipeline.sh "$VCS_TYPE" "$PARAM_USER" "$PARAM_REPO" "$PARAM_BRANCH" "$CUSTOM_PARAMS"
62+
else
63+
/tmp/swissknife/trigger_pipeline.sh "$VCS_TYPE" "$PARAM_USER" "$PARAM_REPO" -t "$PARAM_TAG" "$CUSTOM_PARAMS"
64+
fi
5065
fi

src/commands/trigger-pipeline.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
description: |
2-
Triggers a pipeline on given branch. Also allows to installthe trigger script and not trigger into
2+
Triggers a pipeline on given branch. Also allows to install the trigger script and not trigger into
33
/tmp/swissknife/trigger_pipeline.sh
44
it can be called with the arguments as follows
55
/tmp/swissknife/trigger_pipeline.sh vcstype username reponame branch '{"custom_params": "here"}'
6+
OR
7+
/tmp/swissknife/trigger_pipeline.sh vcstype username reponame -t tag '{"custom_params": "here"}'
68
parameters:
79
repo-name:
810
type: env_var_name
@@ -20,6 +22,10 @@ parameters:
2022
description: The branch to trigger the pipeline on
2123
type: env_var_name
2224
default: CIRCLE_BRANCH
25+
tag:
26+
description: The tag to trigger the pipeline on
27+
type: env_var_name
28+
default: CIRCLE_TAG
2329
custom-parameters:
2430
description: Custom parameters passed to the pipeline
2531
type: string
@@ -37,5 +43,6 @@ steps:
3743
PARAM_USER_ENV_VAR: << parameters.user >>
3844
PARAM_REPO_ENV_VAR: << parameters.repo-name >>
3945
PARAM_BRANCH_ENV_VAR: << parameters.branch >>
46+
PARAM_TAG_ENV_VAR: << parameters.tag >>
4047
CUSTOM_PARAMS: << parameters.custom-parameters >>
4148
command: << include(../scripts/trigger-pipeline.sh) >>

0 commit comments

Comments
 (0)