diff --git a/jobs-dsl/jobs/Cloud/Apps-Frontend/cloud_messenger_host.groovy b/jobs-dsl/jobs/Cloud/Apps-Frontend/cloud_messenger_host.groovy new file mode 100644 index 0000000..e8213ef --- /dev/null +++ b/jobs-dsl/jobs/Cloud/Apps-Frontend/cloud_messenger_host.groovy @@ -0,0 +1,92 @@ +multibranchPipelineJob('Cloud/Apps-Frontend/cloud-messenger-host') { + description('cloud-messenger-host') + displayName('cloud-messenger-host') + factory { + remoteJenkinsFileWorkflowBranchProjectFactory { + localMarker('') + matchBranches(true) + fallbackBranch('master') + lookupInParameters(false) + remoteJenkinsFile('pipelines/Cloud/Apps-Frontend/cloud-messenger-host.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-host') + credentialsId("${JENKINS_GIT_CREDENTIALS_HTTP}") + id('Apps-Frontend/cloud-messenger-host') + 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-Frontend/cloud-messenger-host.groovy b/pipelines/Cloud/Apps-Frontend/cloud-messenger-host.groovy new file mode 100644 index 0000000..72e3b56 --- /dev/null +++ b/pipelines/Cloud/Apps-Frontend/cloud-messenger-host.groovy @@ -0,0 +1,82 @@ +@Library('shared-lib') _ + +import tech.avroid.kube.PodTemplates +import tech.avroid.scm.Git +import tech.avroid.jenkins.Notifications + +properties([ + buildDiscarder(logRotator(daysToKeepStr: '10', + numToKeepStr: '10')), + disableConcurrentBuilds() +]) + +String repoPath = 'Apps-Frontend/cloud-messenger-host.git' +String maintainerUser = '' +String appVersion = '' +String publishBranch = 'develop' +String imageTag = '' +Map gitVars = [:] + +Git git = new Git(this, env.JENKINS_GIT_CREDENTIALS_SSH) +PodTemplates slaveTemplates = new PodTemplates(this, env.JENKINS_DOCKER_REGISTRY, ["${env.JENKINS_K8S_HARBOR_SECRET}"]) + +String branch = git.getBranch() + +slaveTemplates.jnlp { + slaveTemplates.docker { + slaveTemplates.nodejs(imageVersion='18.19-alpine3.18') { + try { + node(POD_LABEL){ + stage('Download sources') { + gitVars = git.clone([urlRepo: "${env.JENKINS_GIT_REPOSITORY_SSH_URL}/${repoPath}", branch: branch]) + } + + container('nodejs'){ + stage('build app'){ + sh """#!/bin/sh + npm config set registry ${env.JENKINS_NEXUS_NPM_REPOSITORY} + npm install + npm run build + """ + } + } + + container('docker'){ + stage('build and push image'){ + appVersion = readJSON(file: 'package.json').version + imageTag = "${appVersion}-${gitVars.GIT_COMMIT.take(5)}" + docker.withRegistry("https://${env.JENKINS_DOCKER_REGISTRY}", env.JENKINS_HARBOR_CREDENTIALS) { + + Object buildImage = docker.build( + "${env.JENKINS_DOCKER_REGISTRY}/cloud/cloud-messenger-host:${imageTag}", + "-f Dockerfile ." + ) + + if (branch == publishBranch) { + maintainerUser = 'rishat.gabaidullov@avroid.team' + buildImage.push() + } + } + } + } + } + } 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 + ) + } + } + } +}