forked from SUSE/susemanager-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile_prs_ruby_rubocop
100 lines (93 loc) · 3.6 KB
/
Jenkinsfile_prs_ruby_rubocop
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env groovy
properties([
buildDiscarder(logRotator(numToKeepStr: '500'))
])
pipeline {
options {
timeout(time: 30, unit: 'MINUTES')
}
parameters {
string(defaultValue: '', description: 'Gitarro PR', name: 'GITARRO_PR_NUMBER')
string(defaultValue: '', description: 'SUSE Manager PR', name: 'PR_NUMBER')
booleanParam(defaultValue: true, description: 'Clean up workspace after a successful execution.', name: 'cleanWorkspace')
}
environment {
repository = "SUSE/spacewalk"
context = "ruby_rubocop"
description = "rubocop checkstyle"
git_fs = "${env.WORKSPACE}"
filter = 'testsuite/'
test = "${env.WORKSPACE}/jenkins_pipelines/manager_prs/tests_files/rubocop.sh"
gitarro_common_params = "-r ${repository} -c ${context} -d ${description} -f ${filter} -t ${test} -g ${git_fs}"
gitarro_cmd = 'gitarro.ruby2.5'
gitarro_local = 'ruby gitarro/gitarro.rb'
runtest = "${gitarro_common_params} -u ${env.BUILD_URL}"
}
agent { label 'suse-manager-unit-tests' }
stages {
stage('Clean Up Workspace') {
when {
anyOf {
changeset "**/*.rb"
changeset ".github/workflows/rubocop.yml"
changeset "testsuite/.rubocop.yml"
changeset "testsuite/.rubocop_todo.yml"
changeset "testsuite/Gemfile"
changeset "testsuite/Rakefile"
}
}
steps {
echo 'Clean up previous workspace'
cleanWs()
echo 'Check out SCM'
checkout scm
script {
if (params.GITARRO_PR_NUMBER != '') {
echo 'Check out Gitarro PR'
dir('gitarro') {
checkout([$class : 'GitSCM', branches: [[name: "FETCH_HEAD"]],
extensions : [[$class: 'LocalBranch']],
userRemoteConfigs: [[refspec: "+refs/pull/${params.GITARRO_PR_NUMBER}/head:refs/remotes/origin/PR-${params.GITARRO_PR_NUMBER}", url: "https://[email protected]/openSUSE/gitarro"]]])
}
}
}
}
}
stage('Run tests against PR') {
when {
anyOf {
changeset "**/*.rb"
changeset ".github/workflows/rubocop.yml"
changeset "testsuite/.rubocop.yml"
changeset "testsuite/.rubocop_todo.yml"
changeset "testsuite/Gemfile"
changeset "testsuite/Rakefile"
}
}
steps {
echo 'Run tests!'
script {
commands = "${gitarro_cmd} ${runtest}"
if (params.GITARRO_PR_NUMBER != '') {
commands = "${gitarro_local} ${runtest}"
}
if (params.PR_NUMBER != '') {
commands = "${commands} -P ${params.PR_NUMBER}"
currentBuild.displayName = "PR: ${params.PR_NUMBER}"
}
}
sh "export PRODUCT=SUSE-Manager && ${commands}"
}
}
}
post {
success {
script {
if (params.cleanWorkspace == true) {
echo 'Clean up current workspace, when job success.'
cleanWs()
}
}
}
}
}