-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
63 lines (61 loc) · 1.77 KB
/
Jenkinsfile
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
void sbtAction(String task) {
container('sbt-container') {
sh '''
echo "
realm=Sonatype Nexus Repository Manager
host=${NEXUS}
user=${NEXUS_CREDENTIALS_USR}
password=${NEXUS_CREDENTIALS_PSW}" > ~/.sbt/.credentials
'''
sh "sbt -Dsbt.log.noformat=true ${task}"
}
}
void updateGithubCommit(String status) {
def token = '${GITHUB_PAT_PSW}'
sh """
curl --silent --show-error \
"https://api.github.com/repos/pagopa/${REPO_NAME}/statuses/${GIT_COMMIT}" \
--header "Content-Type: application/json" \
--header "Authorization: token ${token}" \
--request POST \
--data "{\\"state\\": \\"${status}\\",\\"context\\": \\"Jenkins Continuous Integration\\", \\"description\\": \\"Build ${BUILD_DISPLAY_NAME}\\"}" &> /dev/null
"""
}
pipeline {
agent { label 'sbt-template' }
environment {
GITHUB_PAT = credentials('github-pat')
NEXUS = "${env.NEXUS}"
NEXUS_CREDENTIALS = credentials('pdnd-nexus')
MAVEN_REPO = "${env.MAVEN_REPO}"
// GIT_URL has the shape [email protected]:pagopa/REPO_NAME.git so we extract from it
REPO_NAME="""${sh(returnStdout:true, script: 'echo ${GIT_URL} | sed "s_https://github.com/pagopa/\\(.*\\)\\.git_\\1_g"')}""".trim()
}
stages {
stage('Testing Library') {
steps {
updateGithubCommit 'pending'
sbtAction 'test'
}
}
stage('Publishing Library on Nexus') {
when {
anyOf {
branch pattern: "[0-9]+\\.[0-9]+\\.x", comparator: "REGEXP"
buildingTag()
}
}
steps {
sbtAction 'publish'
}
}
}
post {
success {
updateGithubCommit 'success'
}
failure {
updateGithubCommit 'failure'
}
}
}