-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathJenkinsfile-example
72 lines (66 loc) · 3.07 KB
/
Jenkinsfile-example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Jenkinsfile example for checking dependencies from version control against a
// Tidelift Catalog
// Set build environment variable for the Tidelift API Key
// This example is for maven
pipeline {
agent any
tools {
maven 'Maven 3.8.1'
}
environment {
// Always store API keys in Jenkins credential store
// ORG key should be either an Organization API key or Project API key
TIDELIFT_ORG_API_KEY = credentials('tidlift-org-api-key')
// Only needed for automated project creation
TIDELIFT_BOT_USER_API_KEY = credentials('tidlift-bot-user-api-key')
// These are needed to run alignments and also to create the project. Ideally these are read from
// configuration in Jenkins or from local metadata stored in the repository being checked out.
TIDELIFT_PROJECT_NAME = 'project-name'
TIDELIFT_ORGANIZATION = 'team/<tidelift-org>'
TIDELIFT_CATALOG = 'catalog-name'
}
// Checkout code from your version control system
stages {
stage('Checkout code') {
steps {
git '<url-to-checkout>'
}
}
// Download the Tidelift CLI and make it executable
stage('Downloading Tidelift CLI') {
steps {
sh 'curl -s -o ./tidelift https://download.tidelift.com/cli/tidelift'
sh 'chmod +x ./tidelift'
}
}
// OPTIONAL: Create Tidelift project if it does not already exist. Here we are running the create command via CLI.
// If the project is not known, it will be created and logged. If it is known, we catch the response and move on.
// stage('Creating project if does not exist'){
// steps {
// Need to use a bot user API key in order to create the project as project and organization keys do not allow project
// creation.
// withEnv(['TIDELIFT_API_KEY=${TIDELIFT_BOT_USER_API_KEY}']){
// The command to create a new project will create an error if the project exists. Catch and move on to alignment if
// project exists.
// catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE'){
// sh './tidelift projects new ${TIDELIFT_PROJECT_NAME} --force --organization ${TIDELIFT_ORGANIZATION} --catalog ${TIDELIFT_CATALOG}'
// echo 'Project does not exist in Tidelift.'
// echo "Created project in Tidelift."
// }
// }
// }
// }
// Run Tidelift Catalog alignment and save output to Tidelift
// Ensure Organization or Project API key is being used to run the alignment
// Optional step catches any mis-alignments reported back as to not break builds, but will log the mis-alignment.
stage('Running Tidelift Alignment') {
steps {
withEnv(['TIDELIFT_API_KEY=${TIDELIFT_ORG_API_KEY}']){
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh "./tidelift alignment save --wait --project ${TIDELIFT_PROJECT_NAME} --organization ${TIDELIFT_ORGANIZATION}"
}
}
}
}
}
}