Jenkins
Port's Jenkins integration allows you to model Jenkins resources in your software catalog and ingest data into them.
Prerequisites
-
Jenkins API token — In Jenkins, click your username and navigate to Configure > API Token to generate a token to use as the
JENKINS_TOKEN. -
Required plugins — Install the following via Manage Jenkins > Plugins:
- People View — Required for user information API (Jenkins 2.452 and above).
- Pipeline: Stage View — Required for fetching pipeline stage data.
Setup
Choose your preferred installation method below. Not sure which to pick? See the installation methods overview.
Create jenkins blueprints
Before configuring the integration, create the following blueprints in your Port organization.
Follow the instructions below to create the blueprints:
-
Go to your Builder page.
-
Click + Blueprint.
-
Click the
{...} Edit JSONbutton in the top right corner of the form. -
Copy and paste each blueprint JSON from the sections below. Recommended order: job, then build, then user.
Jenkins Job blueprint (click to expand)
{"identifier": "jenkinsJob","description": "This blueprint represents a job event from Jenkins","title": "Jenkins Job","icon": "Jenkins","schema": {"properties": {"jobName": {"type": "string","title": "Job Name"},"jobStatus": {"type": "string","title": "Job Status","enum": ["created", "unknown", "passing", "failing"],"enumColors": {"passing": "green","created": "darkGray","failing": "red","unknown": "orange"}},"timestamp": {"type": "string","format": "date-time","title": "Timestamp","description": "Last updated timestamp of the job"},"url": {"type": "string","title": "Project URL"},"parentJob": {"type": "object","title": "Parent Job"}},"required": []},"mirrorProperties": {},"calculationProperties": {},"relations": {}}Jenkins Build blueprint (click to expand)
{"identifier": "jenkinsBuild","description": "This blueprint represents a build event from Jenkins","title": "Jenkins Build","icon": "Jenkins","schema": {"properties": {"buildStatus": {"type": "string","title": "Build Status","enum": ["SUCCESS", "FAILURE", "UNSTABLE", "ABORTED"],"enumColors": {"SUCCESS": "green","FAILURE": "red","UNSTABLE": "yellow","ABORTED": "darkGray"}},"buildUrl": {"type": "string","title": "Build URL","description": "URL to the build"},"timestamp": {"type": "string","format": "date-time","title": "Timestamp","description": "Last updated timestamp of the build"},"buildDuration": {"type": "number","title": "Build Duration","description": "Duration of the build"}},"required": []},"mirrorProperties": {"previousBuildStatus": {"title": "Previous Build Status","path": "previousBuild.buildStatus"}},"calculationProperties": {},"relations": {"parentJob": {"title": "Jenkins Job","target": "jenkinsJob","required": false,"many": false},"previousBuild": {"title": "Previous Build","target": "jenkinsBuild","required": false,"many": false}}}Jenkins User blueprint (click to expand)
{"identifier": "jenkinsUser","description": "This blueprint represents a jenkins user","title": "Jenkins User","icon": "Jenkins","schema": {"properties": {"url": {"type": "string","title": "URL","format": "url"},"lastUpdateTime": {"type": "string","format": "date-time","title": "Last Update","description": "Last updated timestamp of the user"}},"required": []},"mirrorProperties": {},"calculationProperties": {},"relations": {}} -
Click
Createafter copying each blueprint json to save it and repeat the process for the next blueprint.
The integration also supports mapping Jenkins pipeline stages, but there is no default jenkinsStage blueprint. If you want to ingest stage data, create a custom blueprint that matches the properties in the Stage mapping configuration below.
Configuration
Port integrations use a YAML mapping block to ingest data from the third-party api into Port.
The mapping makes use of the JQ JSON processor to select, modify, concatenate, transform and perform other operations on existing fields and values from the integration API.
Default mapping configuration
This is the default mapping configuration for this integration:
Default mapping configuration (click to expand)
createMissingRelatedEntities: true
deleteDependentEntities: true
resources:
- kind: job
selector:
query: 'true'
port:
entity:
mappings:
identifier: .url | split("://")[1] | sub("^.*?/"; "") | gsub("%20"; "-") | gsub("%252F"; "-") | gsub("/"; "-") | .[:-1]
title: .fullName
blueprint: '"jenkinsJob"'
properties:
jobName: .name
url: .url
jobStatus: '{"notbuilt": "created", "blue": "passing", "red": "failing"}[.color]'
timestamp: .time
parentJob: .__parentJob
- kind: build
selector:
query: 'true'
maxBuildsPerJob: 100
port:
entity:
mappings:
identifier: >-
.url | split("://")[1] | sub("^.*?/"; "") | gsub("%20"; "-") | gsub("%252F"; "-") | gsub("/"; "-") | .[:-1]
title: .displayName
blueprint: '"jenkinsBuild"'
properties:
buildStatus: .result
buildUrl: .url
buildDuration: .duration
timestamp: .timestamp / 1000 | todate
relations:
parentJob: .url | split("://")[1] | sub("^.*?/"; "") | gsub("%20"; "-") | gsub("%252F"; "-") | gsub("/"; "-") | .[:-1] | gsub("-[0-9]+$"; "")
previousBuild: >-
if .previousBuild then (.previousBuild.url | split("://")[1] |
sub("^.*?/"; "") | gsub("%20"; "-") | gsub("%252F"; "-") |
gsub("/"; "-") | .[:-1]) else null end
- kind: user
selector:
query: 'true'
port:
entity:
mappings:
identifier: .user.id
title: .user.fullName
blueprint: '"jenkinsUser"'
properties:
url: .user.absoluteUrl
lastUpdateTime: if .lastChange then (.lastChange/1000) else now end | strftime("%Y-%m-%dT%H:%M:%SZ")
Monitoring and sync status
To learn more about how to monitor and check the sync status of your integration, see the relevant documentation.
Mapping & selectors per resource
Use the explorer below to view sample payloads and the resulting Port entities for each resource type.