From b62d3069f0de1b4b9a254b4f72709ef90a894d4f Mon Sep 17 00:00:00 2001 From: Rustam Tagaev Date: Wed, 11 Dec 2024 19:11:18 +0300 Subject: [PATCH] [DO-1395] add_new_job (!56) Co-authored-by: Rustam Tagaev Reviewed-on: https://git.avroid.tech/DevOps/jenkins-pipelines/pulls/56 Reviewed-by: Denis Patrakeev Co-authored-by: Rustam Tagaev Co-committed-by: Rustam Tagaev --- jobs-dsl/folders/Cloud.groovy | 5 + .../Apps-Backend/avroid_service_lib.groovy | 8 +- .../cloud_messenger_core_api.groovy | 8 +- .../cloud_messenger_uikit.groovy | 92 +++++++++++++++++++ .../Apps-Backend/avroid-service-lib.groovy | 1 - .../cloud-messenger-uikit.groovy | 73 +++++++++++++++ 6 files changed, 178 insertions(+), 9 deletions(-) create mode 100644 jobs-dsl/jobs/Cloud/Apps-Frontend/cloud_messenger_uikit.groovy create mode 100644 pipelines/Cloud/Apps-Frontend/cloud-messenger-uikit.groovy diff --git a/jobs-dsl/folders/Cloud.groovy b/jobs-dsl/folders/Cloud.groovy index 7beb866..2f07870 100644 --- a/jobs-dsl/folders/Cloud.groovy +++ b/jobs-dsl/folders/Cloud.groovy @@ -8,6 +8,11 @@ folder('Cloud/Apps-Backend') { description('Apps-Backend organization') } +folder('Cloud/Apps-Frontend') { + displayName('Apps-Frontend') + description('Apps-Frontend organization') +} + folder('Cloud/Deploy') { displayName('Deploy') description('Deploy jobs') diff --git a/jobs-dsl/jobs/Cloud/Apps-Backend/avroid_service_lib.groovy b/jobs-dsl/jobs/Cloud/Apps-Backend/avroid_service_lib.groovy index ed7194c..871cc02 100644 --- a/jobs-dsl/jobs/Cloud/Apps-Backend/avroid_service_lib.groovy +++ b/jobs-dsl/jobs/Cloud/Apps-Backend/avroid_service_lib.groovy @@ -12,8 +12,8 @@ multibranchPipelineJob('Cloud/Apps-Backend/avroid-service-lib') { gitSCM { userRemoteConfigs { userRemoteConfig { - url('https://git.avroid.tech/DevOps/jenkins-pipelines.git') - credentialsId('user-jenkins-in-gitea') + url("${JENKINS_GIT_REPOSITORY_URL}/DevOps/jenkins-pipelines.git") + credentialsId("${JENKINS_GIT_CREDENTIALS_HTTP}") name('') refspec('') } @@ -29,10 +29,10 @@ multibranchPipelineJob('Cloud/Apps-Backend/avroid-service-lib') { branchSource { source { giteaSCMSource { - serverUrl('https://git.avroid.tech') + serverUrl("${JENKINS_GIT_REPOSITORY_URL}") repoOwner('Apps-Backend') repository('avroid-service-lib') - credentialsId('user-jenkins-in-gitea') + credentialsId("${JENKINS_GIT_CREDENTIALS_HTTP}") id('Apps-Backend/avroid-service-lib') traits { giteaBranchDiscovery { diff --git a/jobs-dsl/jobs/Cloud/Apps-Backend/cloud_messenger_core_api.groovy b/jobs-dsl/jobs/Cloud/Apps-Backend/cloud_messenger_core_api.groovy index 6af4c5e..9e66a91 100644 --- a/jobs-dsl/jobs/Cloud/Apps-Backend/cloud_messenger_core_api.groovy +++ b/jobs-dsl/jobs/Cloud/Apps-Backend/cloud_messenger_core_api.groovy @@ -12,8 +12,8 @@ multibranchPipelineJob('Cloud/Apps-Backend/cloud-messenger-core-api') { gitSCM { userRemoteConfigs { userRemoteConfig { - url('https://git.avroid.tech/DevOps/jenkins-pipelines.git') - credentialsId('user-jenkins-in-gitea') + url("${JENKINS_GIT_REPOSITORY_URL}/DevOps/jenkins-pipelines.git") + credentialsId("${JENKINS_GIT_CREDENTIALS_HTTP}") name('') refspec('') } @@ -29,10 +29,10 @@ multibranchPipelineJob('Cloud/Apps-Backend/cloud-messenger-core-api') { branchSource { source { giteaSCMSource { - serverUrl('https://git.avroid.tech') + serverUrl("${JENKINS_GIT_REPOSITORY_URL}") repoOwner('Apps-Backend') repository('cloud-messenger-core-api') - credentialsId('user-jenkins-in-gitea') + credentialsId("${JENKINS_GIT_CREDENTIALS_HTTP}") id('Apps-Backend/cloud-messenger-core-api') traits { giteaBranchDiscovery { diff --git a/jobs-dsl/jobs/Cloud/Apps-Frontend/cloud_messenger_uikit.groovy b/jobs-dsl/jobs/Cloud/Apps-Frontend/cloud_messenger_uikit.groovy new file mode 100644 index 0000000..b441bc8 --- /dev/null +++ b/jobs-dsl/jobs/Cloud/Apps-Frontend/cloud_messenger_uikit.groovy @@ -0,0 +1,92 @@ +multibranchPipelineJob('Cloud/Apps-Frontend/cloud-messenger-uikit') { + description('cloud-messenger-uikit') + displayName('cloud-messenger-uikit') + factory { + remoteJenkinsFileWorkflowBranchProjectFactory { + localMarker('') + matchBranches(true) + fallbackBranch('master') + lookupInParameters(false) + remoteJenkinsFile('pipelines/Cloud/Apps-Frontend/cloud-messenger-uikit.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-Frontend') + repository('cloud-messenger-uikit') + credentialsId("${JENKINS_GIT_CREDENTIALS_HTTP}") + id('Apps-Frontend/cloud-messenger-uikit') + 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') + } + } +} diff --git a/pipelines/Cloud/Apps-Backend/avroid-service-lib.groovy b/pipelines/Cloud/Apps-Backend/avroid-service-lib.groovy index 03a4f98..f29bfcf 100644 --- a/pipelines/Cloud/Apps-Backend/avroid-service-lib.groovy +++ b/pipelines/Cloud/Apps-Backend/avroid-service-lib.groovy @@ -18,7 +18,6 @@ Nexus nexus = new Nexus(this, env.JENKINS_NEXUS_URL, env.JENKINS_NEXUS_CREDENTIA String repoPath = 'Apps-Backend/avroid-service-lib.git' String nexusRepoName = 'tavro-cloud-pypi-release' -String artifactUrl = "${env.JENKINS_NEXUS_URL}/repository/${nexusRepoName}" String localArtifactDir = './dist' Map gitVars = [:] diff --git a/pipelines/Cloud/Apps-Frontend/cloud-messenger-uikit.groovy b/pipelines/Cloud/Apps-Frontend/cloud-messenger-uikit.groovy new file mode 100644 index 0000000..fb68786 --- /dev/null +++ b/pipelines/Cloud/Apps-Frontend/cloud-messenger-uikit.groovy @@ -0,0 +1,73 @@ +@Library('shared-lib') _ + +import tech.avroid.kube.PodTemplates +import tech.avroid.scm.Git +import tech.avroid.api.Nexus +import tech.avroid.jenkins.Notifications + +properties([ + buildDiscarder(logRotator(artifactDaysToKeepStr: '', + artifactNumToKeepStr: '30', + daysToKeepStr: '', + numToKeepStr: '30')), + disableConcurrentBuilds() +]) + +String repoPath = 'Apps-Frontend/cloud-messenger-uikit.git' +String publishBranch = 'develop' +String nexusRepoName = 'tavro-cloud-npm-feature' +String maintainerUser = '' + +Git git = new Git(this, env.JENKINS_GIT_CREDENTIALS_SSH) +PodTemplates slaveTemplates = new PodTemplates(this, env.JENKINS_DOCKER_REGISTRY, ["${env.JENKINS_K8S_HARBOR_SECRET}"]) +Nexus nexus = new Nexus(this, env.JENKINS_NEXUS_URL, env.JENKINS_NEXUS_CREDENTIALS) + +slaveTemplates.jnlp { + slaveTemplates.nodejs(imageVersion='18.16-alpine3.18') { + try { + node(POD_LABEL){ + stage('Download sources') { + git.clone([urlRepo: "${env.JENKINS_GIT_REPOSITORY_SSH_URL}/${repoPath}", branch: git.getBranch()]) + } + + container('nodejs'){ + stage('build'){ + sh """ + npm config set registry ${env.JENKINS_NEXUS_NPM_REPOSITORY} + npm install + npm run build + npm pack + """ + } + + if (git.getBranch() == publishBranch){ + maintainerUser = 'rishat.gabaidullov@avroid.team' + + stage('upload artifact'){ + String artifact = sh( script: "ls *.tgz", returnStdout: true).trim() + + nexus.uploadNpmArtifact(artifact: "${artifact}", repository: nexusRepoName + ) + } + } + } + } + } catch(err) { + errorMessage = err.getMessage() + + println 'ERROR: ' + errorMessage + + currentBuild.result = 'FAILURE' + + String emailSubject = "${currentBuild.currentResult}. Pipeline task: ${currentBuild.fullDisplayName}" + + Notifications.email( + script: this, + subject: emailSubject, + errorString: errorMessage, + recipientProviders: [], + to: maintainerUser + ) + } + } +}