Create Docker action container using IBM Cloud Functions/OpenWhisk to start a Delivery Pipeline run.
-
Build and push the docker image containing the
pipeline-run.sh
script asaction/exec
Reminder: IBM Cloud Function can only use image from public registries - https://cloud.ibm.com/docs/openwhisk?topic=openwhisk-runtimes#openwhisk_ref_docker
docker build -t cdjumpstart/pipeline-run-docker:1.0.0 -t cdjumpstart/pipeline-run-docker:latest . docker push cdjumpstart/pipeline-run-docker:1.0.0 docker push cdjumpstart/pipeline-run-docker:latest
Note: you can reuse the image provided at https://hub.docker.com/repository/docker/cdjumpstart/pipeline-run-docker
-
Create the cloud function namespace and set the CLI context to it
ibmcloud fn namespace create pipeline-trigger-ns ibmcloud fn property set --namespace pipeline-trigger-ns
-
Create IBM Cloud docker action
ibmcloud fn action create pipeline-run --docker cdjumpstart/pipeline-run-docker:1.0.0
-
Configure the action with the default toolchain context and pipeline to execute as function arguments.
The arguments to provide are:
- the region (as
region
argument) - the resource group (as
resource_group
argument) - the toolchain id (as
toolchain_id
argument) - the pipeline id (as
pipeline_id
argument) - (optional) the stage id (as
stage_id
argument) if the goal is to run a specific stage of the pipeline
Notes:
- You can use the ibmcloud dev plugin to find easily the IDs.
- Those arguments will be the default one for the function.
ibmcloud fn action update pipeline-run \ --param region us-south \ --param resource_group default \ --param toolchain_id 93918ab6-df3b-40e8-bbe7-d36a7aaadb1b \ --param pipeline_id 1c14d6f5-32d9-4e59-9d7c-5713e6fbd6d6
- the region (as
-
Configure the authentication
As described in https://cloud.ibm.com/docs/openwhisk?topic=openwhisk-namespaces#targeting-namespaces, giving Resource group and Toolchain access to IBM Cloud function service ID corresponding to the used namespace for IBM Cloud function provide a mechanism to set the apikey (
__OW_IAM_NAMESPACE_API_KEY
) used foribmcloud login
in thepipeline-run.sh
script.Use the IAM UI to add access to the resource group(s) and the toolchain(s) that will be launched by the IBM Cloud Function action.
Notes:
- The
Editor
role must be given to the service id for the target Toolchain(s) in order to be able to run the pipeline(s). - If only
Operator
role is given, then to be able to run a pipeline, the stage started when running the pipeline needs to be configured in the input section to allow this stage to be run manually by all toolchain members. By default only toolchain members with write privileges can manually run a stage. When checked all toolchain members are granted this privilege too.
Alternative: Define an
ibm_cloud_api_key
argument to the action with an arbitrary api key allowing to access the given pipelineibmcloud fn action update pipeline-run \ --param region us-south \ --param resource_group default \ --param toolchain_id 93918ab6-df3b-40e8-bbe7-d36a7aaadb1b \ --param pipeline_id 1c14d6f5-32d9-4e59-9d7c-5713e6fbd6d6 \ --param ibm_cloud_api_key <api key>
- The
With the pipeline-run function defined, you can now define a time trigger to start it. See https://cloud.ibm.com/docs/openwhisk?topic=openwhisk-triggers
In the remaining section, we will define a trigger that will start a run of the configured pipeline every 2 minutes
- Define the time trigger
ibmcloud fn trigger create pipeline-run-every-2-minutes \ --feed /whisk.system/alarms/interval \ --param minutes 2
Note: if using Git bash on Windows, use this command to define the trigger:
ibmcloud fn trigger create pipeline-run-every-2-minutes \ --feed '//whisk.system\alarms\interval' \ --param minutes 2
2) Create the rule that associate the trigger to the function
ibmcloud fn rule create pipeline-run-rule pipeline-run-every-2-minutes pipeline-run
- Optionnaly, you can monitor the activity by polling for the activation logs
ibmcloud fn activation poll