forked from snyk-labs/snyk-cicd-integration-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile_unused
More file actions
62 lines (56 loc) · 1.56 KB
/
Jenkinsfile_unused
File metadata and controls
62 lines (56 loc) · 1.56 KB
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
pipeline {
agent any
tools {
// Must match Manage Jenkins > Tools > JDK
jdk 'jdk-21'
}
stages {
stage('Initialize') {
steps {
script {
echo "Checking environment..."
sh 'java -version'
}
}
}
stage('Build') {
steps {
echo 'Building...'
// sh './mvnw clean install'
}
}
stage('Security Scan') {
steps {
// FIX 2: Snyk plugin 'snykSecurity' step
// Note: We use the ID directly here. The plugin handles the binding internally.
snykSecurity(
snykInstallation: 'Snyk@latest',
snykTokenId: 'organisational-snyk-api-token',
failOnIssues: true
)
}
}
stage('Deploy') {
when { branch 'main' }
steps {
echo 'Deploying...'
}
}
}
post {
always {
// FIX 3: Prevent "MissingContextVariableException"
// We check if the workspace (FilePath) is still accessible before cleaning
script {
if (getContext(hudson.FilePath)) {
cleanWs()
} else {
echo "Workspace not found, skipping cleanWs."
}
}
}
failure {
echo "Pipeline failed. Check Snyk or Build logs above."
}
}
}