Pipeline Policies are runtime validations that work for both scripted and declarative pipelines, and provide administrators a way to include warnings for or block the execution of pipelines that do not comply with the policies applied to your managed controller.
In this lab you will use CloudBees CI CasC for controllers to create a Pipeline Policy to enforce that all Pipeline jobs that run on your CloudBees CI managed controller (Jenkins instance) have a maximum 30 minute global timeout
set.
cloudbees-ci-config-bundle
repository in GitHub and click on the Pull requests link. cloudbees-pipeline-policies
configuration at the top of the jenkins.yaml
file. We also updated the bundle version and the Jenkins system message. If you don’t see the new version available then click the Check for Updates button. Remember, the config-bundle-ops pipeline is triggering a job on another controller, so the update won’t be available until that job has completed.
After the updated configuration bundle has finished loading, click on the Pipeline Policies link in the left menu.
Next, on the Pipeline Policies screen, you will see a policy with the following settings - matching the configuration from the updated CasC bundle:
Navigate to the config-bundle-ops Mutlibranch project in the template-jobs folder, click on the main branch job and then click the Build Now link in the left menu.
Navigate to the logs for that build and you will see that the build failed due to Validation Errors.
To fix this we will have to once again update the Jenkinsfile
of the CloudBees CI Configuration Bundle template in your copy of the pipeline-template-catalog
repository - remember, even though we are building from the cloudbees-ci-config-bundle
repository, the Jenkinsfile
is actually coming from the CloudBees CI Configuration Bundle template. Navigate to that Jenkinsfile
and click the pencil icon to open it in the GitHub file editor.
In the GitHub file editor, change the time
value of the timeout
pipeline option
from 60
to 10
(it needs to be 30 minutes or less to successfully validate against the Timeout policy) and then click the Commit changes (directly to the main
branch) button to commit the updated Jenkinsfile
to your main branch.
Next, to ensure that we are using the updated CloudBees CI Configuration Bundle template, we will check the Pipeline Template Catalog Import Log. Navigate to the top-level of your CloudBees CI managed controller and click on Pipeline Template Catalogs link in the left menu and then click the workshopCatalog link.
Merging the updated Jenkinsfile
for that template will trigger a GitHub webhook resulting in a re-import of the CloudBees CI Workshop Template Catalog.
For instructor led workshops please return to the workshop slides