Skip to content

Commit aae19c4

Browse files
committed
Example script of adding run-script task to pipelines
This commit proposes a script that utilizes pipeline-migration-tool to add run-script to pipelines. That should make it a little bit easier for users by running the script with little initial configuration than opening each YAML file and doing manual YAML modification by copy/paste. Signed-off-by: Chenxiong Qi <[email protected]>
1 parent 18ff781 commit aae19c4

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

modules/patterns/pages/running-user-scripts-on-the-build-pipeline.adoc

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,54 @@ When the script is the tool generating the `Containerfile`, you need to modify `
113113
==== ansible-builder to build Ansible Execution Environments
114114

115115
A link:https://github.com/Zokormazo/konflux-execution-environment-example/pull/2/files[sample repository] has been prepared to show how to use this task to build Ansible Execution Environments.
116+
117+
=== Example script of adding run-script to pipelines
118+
119+
This script utilizes link:https://github.com/konflux-ci/pipeline-migration-tool/[pipeline-migration-tool] to add `run-script` task and all the related changes to pipelines.
120+
121+
[source,bash]
122+
----
123+
pipeline_files=(.tekton/pull-request.yaml) <1>
124+
build_task=build-container <2>
125+
for pipeline_file in ${pipeline_files[@]}
126+
do
127+
pmt add-task \
128+
--run-after prefetch-dependencies \
129+
--bundle-ref quay.io/konflux-ci/tekton-catalog/task-run-script-oci-ta:0.1@sha256:834a934f1e631a79aea7f2d001162cf90086e664e648c8ca15b69ad9798571ee \
130+
--param 'ociStorage=$(params.output-image).script' \
131+
--param 'ociArtifactExpiresAfter=$(params.image-expires-after)' \
132+
--param 'SCRIPT_RUNNER_IMAGE=quay.io/my-script-runner-image:latest@sha256:digest' \
133+
--param 'SCRIPT=my-script' \
134+
--param 'HERMETIC=$(params.hermetic)' \
135+
--param 'SOURCE_ARTIFACT=$(tasks.prefetch-dependencies.results.SOURCE_ARTIFACT)' \
136+
run-script \
137+
"$pipeline_file"
138+
139+
pmt modify -f "$pipeline_file" task "$build_task" remove-param SOURCE_ARTIFACT
140+
pmt modify -f "$pipeline_file" task "$build_task" add-param \
141+
SOURCE_ARTIFACT \
142+
"\$(tasks.run-script.results.SCRIPT_ARTIFACT)"
143+
144+
pmt modify -f "$pipeline_file" task "$build_task" add-param \
145+
--type array \
146+
ADDITIONAL_BASE_IMAGES \
147+
"\$(tasks.run-script.results.SCRIPT_RUNNER_IMAGE_REFERENCE)"
148+
149+
yaml_path=$(yq "
150+
.spec.pipelineSpec.tasks[]
151+
| select(.name == \"${build_task}\")
152+
| .runAfter[] | select(. == \"prefetch-dependencies\")
153+
| path
154+
" "$pipeline_file")
155+
pmt modify -f "$pipeline_file" generic replace "$yaml_path" run-script
156+
157+
pmt modify -f "$pipeline_file" task push-dockerfile remove-param SOURCE_ARTIFACT
158+
pmt modify -f "$pipeline_file" task push-dockerfile add-param \
159+
SOURCE_ARTIFACT \
160+
"\$(tasks.run-script.results.SCRIPT_ARTIFACT)"
161+
done
162+
----
163+
164+
<1> Replace with your Pipeline/PipelineRun YAML files.
165+
166+
<2> Aforementioned, choose a proper task name `build-images` or `build-container`.

0 commit comments

Comments
 (0)