If the Jenkins job will update Pipelines resources, you must declare those resources in your Pipelines DSL. For example, a PropertyBag resource can be used to signal Jenkins job results:
resources
resources: - name: app_test_results type: PropertyBag configuration: passing: 0 failing: 0
To initiate the execution of a Jenkins job from within your pipeline, use the Jenkins native step. You must specify the Jenkins Server integration in your integrations
block. If the Jenkins job updates Pipelines resources, you must specify them in the outputResources
block.
Jenkins Step
- name: test_app type: Jenkins configuration: jenkinsJobName: basic-api inputResources: - name: app_docker buildParameters: imageName: ${res_app_docker_imageName} imageTag: ${res_app_docker_imageTag} integrations: - name: myJenkins outputResources: - name: app_test_results
When loaded into Pipelines, the pipeline diagram shows the Jenkins step with a Docker image as an input resource, and the PropertyBag updated by the Jenkins job as an output resource.
Sending Build Parameters to Jenkins
The Jenkins step can pass parameters to the Jenkins job through the buildParameters
property. These values can be fixed or you can use Pipelines environment variables to send dynamic values.
In this example, we specify an Image resource called "app_docker" in the inputResources
of our Jenkins Step. Our buildParameters
property references the resource's environment variables.
Jenkins Parameters
buildParameters: imageName: ${res_app_docker_imageName} imageTag: ${res_app_docker_imageTag} environment: "test"
Note
Run state environment variables are not available to buildParameters.