Skip to content

Commit

Permalink
trigger-pipeline tag support #89 (#90)
Browse files Browse the repository at this point in the history
* trigger-pipeline tag support #89
  • Loading branch information
russelltaga authored Jul 20, 2021
1 parent 05cafe5 commit f8e3773
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
29 changes: 22 additions & 7 deletions scripts/trigger-pipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,28 @@ cat > /tmp/swissknife/trigger_pipeline.sh <<'EOF'
export vcs_type="$1";
export username="$2";
export reponame="$3";
export branch="$4";
export params="$5";
if [[ $4 == "-t" ]]; then
export tag="$5";
export params="$6";
export body='{
"tag": "'$tag'",
"parameters": '"$params"'
}';
else
export branch="$4";
export params="$5";
export body='{
"branch": "'$branch'",
"parameters": '"$params"'
}';
fi
trigger_workflow() {
curl --silent -X POST \
"https://circleci.com/api/v2/project/$vcs_type/$username/$reponame/pipeline?circle-token=${CIRCLE_TOKEN}" \
-H 'Accept: */*' \
-H 'Content-Type: application/json' \
-d '{
"branch": "'$branch'",
"parameters": '"$params"'
}'
-d "${body}"
}
trigger_workflow
Expand All @@ -44,7 +54,12 @@ chmod +x /tmp/swissknife/trigger_pipeline.sh
PARAM_USER=$(printf '%s\n' "${!PARAM_USER_ENV_VAR}")
PARAM_REPO=$(printf '%s\n' "${!PARAM_REPO_ENV_VAR}")
PARAM_BRANCH=$(printf '%s\n' "${!PARAM_BRANCH_ENV_VAR}")
PARAM_TAG=$(printf '%s\n' "${!PARAM_TAG_ENV_VAR}")

if [[ "$SKIP_TRIGGER" == "0" || "$SKIP_TRIGGER" == "false" ]]; then
/tmp/swissknife/trigger_pipeline.sh "$VCS_TYPE" "$PARAM_USER" "$PARAM_REPO" "$PARAM_BRANCH" "$CUSTOM_PARAMS"
if [[ "$PARAM_BRANCH_ENV_VAR" != "" ]]; then
/tmp/swissknife/trigger_pipeline.sh "$VCS_TYPE" "$PARAM_USER" "$PARAM_REPO" "$PARAM_BRANCH" "$CUSTOM_PARAMS"
else
/tmp/swissknife/trigger_pipeline.sh "$VCS_TYPE" "$PARAM_USER" "$PARAM_REPO" -t "$PARAM_TAG" "$CUSTOM_PARAMS"
fi
fi
9 changes: 8 additions & 1 deletion src/commands/trigger-pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
description: |
Triggers a pipeline on given branch. Also allows to installthe trigger script and not trigger into
Triggers a pipeline on given branch. Also allows to install the trigger script and not trigger into
/tmp/swissknife/trigger_pipeline.sh
it can be called with the arguments as follows
/tmp/swissknife/trigger_pipeline.sh vcstype username reponame branch '{"custom_params": "here"}'
OR
/tmp/swissknife/trigger_pipeline.sh vcstype username reponame -t tag '{"custom_params": "here"}'
parameters:
repo-name:
type: env_var_name
Expand All @@ -20,6 +22,10 @@ parameters:
description: The branch to trigger the pipeline on
type: env_var_name
default: CIRCLE_BRANCH
tag:
description: The tag to trigger the pipeline on
type: env_var_name
default: CIRCLE_TAG
custom-parameters:
description: Custom parameters passed to the pipeline
type: string
Expand All @@ -37,5 +43,6 @@ steps:
PARAM_USER_ENV_VAR: << parameters.user >>
PARAM_REPO_ENV_VAR: << parameters.repo-name >>
PARAM_BRANCH_ENV_VAR: << parameters.branch >>
PARAM_TAG_ENV_VAR: << parameters.tag >>
CUSTOM_PARAMS: << parameters.custom-parameters >>
command: << include(../scripts/trigger-pipeline.sh) >>

0 comments on commit f8e3773

Please sign in to comment.