[DO-1452] add build and deploy jobs from msg-auth (!98)
Co-authored-by: Ilya Zaharenkov <ilya.zaharenkov@avroid.tech> Co-authored-by: Denis Patrakeev <denis.patrakeev@avroid.team> Co-authored-by: Rustam Tagaev <rustam.tagaev@avroid.team> Reviewed-on: https://git.avroid.tech/DevOps/jenkins-pipelines/pulls/98 Reviewed-by: Denis Patrakeev <denis.patrakeev@avroid.team> Reviewed-by: Aleksandr Vodyanov <aleksandr.vodyanov@avroid.team> Reviewed-by: Rustam Tagaev <rustam.tagaev@avroid.team>
This commit is contained in:
92
jobs-dsl/jobs/Cloud/Apps-Backend/msg_auth.groovy
Normal file
92
jobs-dsl/jobs/Cloud/Apps-Backend/msg_auth.groovy
Normal file
@@ -0,0 +1,92 @@
|
||||
multibranchPipelineJob('Cloud/Apps-Backend/msg-auth') {
|
||||
description('msg-auth')
|
||||
displayName('msg-auth')
|
||||
factory {
|
||||
remoteJenkinsFileWorkflowBranchProjectFactory {
|
||||
localMarker('')
|
||||
matchBranches(true)
|
||||
fallbackBranch('master')
|
||||
lookupInParameters(false)
|
||||
remoteJenkinsFile('pipelines/Cloud/Apps-Backend/msg-auth.groovy')
|
||||
remoteJenkinsFileSCM {
|
||||
gitSCM {
|
||||
userRemoteConfigs {
|
||||
userRemoteConfig {
|
||||
url("${JENKINS_GIT_REPOSITORY_URL}/DevOps/jenkins-pipelines.git")
|
||||
credentialsId("${JENKINS_GIT_CREDENTIALS_HTTP}")
|
||||
name('')
|
||||
refspec('')
|
||||
}
|
||||
}
|
||||
gitTool('')
|
||||
browser {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
branchSources {
|
||||
branchSource {
|
||||
source {
|
||||
giteaSCMSource {
|
||||
serverUrl("${JENKINS_GIT_REPOSITORY_URL}")
|
||||
repoOwner('Apps-Backend')
|
||||
repository('msg-auth')
|
||||
credentialsId("${JENKINS_GIT_CREDENTIALS_HTTP}")
|
||||
id('Apps-Backend/msg-auth')
|
||||
traits {
|
||||
giteaBranchDiscovery {
|
||||
// 1 Exclude branches that are also filed as PRs
|
||||
// 2 Only branches that are also filed as PRs
|
||||
// 3 Only branches that are also filed as PRs or main
|
||||
// 4 All branches
|
||||
strategyId(1)
|
||||
}
|
||||
|
||||
giteaPullRequestDiscovery {
|
||||
// 1 Merging the pull request with the current target branch revision
|
||||
// 2 The current pull request revision
|
||||
// 3 Both the current pull request revision and the pull request merged with
|
||||
// the current target branch revision
|
||||
strategyId(2)
|
||||
}
|
||||
|
||||
giteaForkDiscovery {
|
||||
// 1 Merging the pull request with the current target branch revision
|
||||
// 2 The current pull request revision
|
||||
// 3 Both the current pull request revision and the pull request merged with
|
||||
// the current target branch revision
|
||||
strategyId(2)
|
||||
trust {
|
||||
giteaTrustContributors()
|
||||
}
|
||||
}
|
||||
|
||||
giteaTagDiscovery()
|
||||
pruneStaleBranch()
|
||||
pruneStaleTag()
|
||||
|
||||
refSpecs {
|
||||
templates {
|
||||
refSpecTemplate {
|
||||
value('+refs/heads/*:refs/remotes/@{remote}/*')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
orphanedItemStrategy {
|
||||
discardOldItems {
|
||||
numToKeep(20)
|
||||
}
|
||||
|
||||
defaultOrphanedItemStrategy {
|
||||
pruneDeadBranches(true)
|
||||
numToKeepStr('10')
|
||||
daysToKeepStr('10')
|
||||
}
|
||||
}
|
||||
}
|
||||
87
jobs-dsl/jobs/Cloud/Deploy/Backend/msg_auth_deploy.groovy
Normal file
87
jobs-dsl/jobs/Cloud/Deploy/Backend/msg_auth_deploy.groovy
Normal file
@@ -0,0 +1,87 @@
|
||||
pipelineJob('Cloud/Deploy/Backend/msg-auth-deploy') {
|
||||
logRotator {
|
||||
numToKeep(10)
|
||||
artifactNumToKeep(10)
|
||||
}
|
||||
|
||||
parameters {
|
||||
choice {
|
||||
name('ENV')
|
||||
choices(['DEV'])
|
||||
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-auth/" +
|
||||
"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-auth-deploy.groovy')
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user