Co-authored-by: Rustam Tagaev <rustam.tagaev@avroid.tech> Reviewed-on: https://git.avroid.tech/DevOps/jenkins-pipelines/pulls/95
88 lines
2.8 KiB
Groovy
88 lines
2.8 KiB
Groovy
pipelineJob('Cloud/Deploy/Backend/msg-profiles-deploy') {
|
|
logRotator {
|
|
numToKeep(10)
|
|
artifactNumToKeep(10)
|
|
}
|
|
|
|
parameters {
|
|
choice {
|
|
name('ENV')
|
|
choices(['DEV', 'TEST'])
|
|
description('Select one of environments')
|
|
}
|
|
choiceParameter {
|
|
name('APP_VERSION')
|
|
randomName('')
|
|
filterable(true)
|
|
filterLength(1)
|
|
script {
|
|
groovyScript {
|
|
fallbackScript {
|
|
script('')
|
|
sandbox(false)
|
|
}
|
|
script {
|
|
sandbox(false)
|
|
script(
|
|
"""
|
|
import groovy.json.JsonSlurperClassic
|
|
import groovy.json.model.*
|
|
import com.cloudbees.plugins.credentials.CredentialsProvider
|
|
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials
|
|
import java.util.regex.Pattern
|
|
|
|
def createGetHttpClient(String url, String jenkinsCreds) {
|
|
def jenkinsCredentials = CredentialsProvider.lookupCredentials(StandardUsernamePasswordCredentials.class)
|
|
def credentials = jenkinsCredentials.findResult { it.id == jenkinsCreds ? it : null }
|
|
String auth = 'robot' + '\$' + 'ci' + ":" + credentials.password
|
|
String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes("utf-8"))
|
|
String authHeaderValue = "Basic " + encodedAuth
|
|
def httpClient = new URL(url).openConnection() as HttpURLConnection
|
|
httpClient.setRequestMethod('GET')
|
|
httpClient.setRequestProperty("Authorization", authHeaderValue)
|
|
httpClient.setRequestProperty("Accept", "application/json")
|
|
return httpClient
|
|
}
|
|
|
|
String harborApiUrl = "https://${JENKINS_DOCKER_REGISTRY}/api/v2.0/projects/cloud/repositories/msg-profiles/" +
|
|
"artifacts?page=1&page_size=100&with_tag=true&sort=-push_time"
|
|
|
|
def httpClientHarbor = createGetHttpClient(harborApiUrl, "${JENKINS_HARBOR_CREDENTIALS}")
|
|
httpClientHarbor.connect()
|
|
|
|
List imageVersions = []
|
|
def harborResponse = new JsonSlurperClassic().parseText(httpClientHarbor.inputStream.text)
|
|
|
|
harborResponse.each { image ->
|
|
image.tags.each { tag ->
|
|
imageVersions.add(tag.name)
|
|
}
|
|
}
|
|
|
|
return imageVersions
|
|
"""
|
|
)
|
|
}
|
|
}
|
|
}
|
|
choiceType('PT_SINGLE_SELECT')
|
|
}
|
|
|
|
}
|
|
|
|
definition {
|
|
cpsScm {
|
|
scm {
|
|
git {
|
|
remote {
|
|
url("${JENKINS_GIT_REPOSITORY_URL}/DevOps/jenkins-pipelines.git")
|
|
credentials("${JENKINS_GIT_CREDENTIALS_HTTP}")
|
|
}
|
|
branch('master')
|
|
}
|
|
}
|
|
scriptPath('pipelines/Cloud/Deploy/Backend/msg-profiles-deploy.groovy')
|
|
}
|
|
}
|
|
}
|