From ee6b3e4c9c1976123c0882ffb89895a60a1078af Mon Sep 17 00:00:00 2001 From: jstastny-cz Date: Fri, 3 May 2024 14:34:34 +0200 Subject: [PATCH] Revert "adjust deploy operation" This reverts commit 49603f3090750d98e0e08f6166bc02f16853647b. --- .ci/jenkins/Jenkinsfile.deploy | 107 +++++++++++++++++--------- .ci/jenkins/Jenkinsfile.weekly.deploy | 41 ++++++---- .ci/jenkins/dsl/jobs.groovy | 5 ++ 3 files changed, 99 insertions(+), 54 deletions(-) diff --git a/.ci/jenkins/Jenkinsfile.deploy b/.ci/jenkins/Jenkinsfile.deploy index 765e91109a..cce026209a 100644 --- a/.ci/jenkins/Jenkinsfile.deploy +++ b/.ci/jenkins/Jenkinsfile.deploy @@ -2,6 +2,7 @@ import org.jenkinsci.plugins.workflow.libs.Library @Library('jenkins-pipeline-shared-libraries')_ import org.kie.jenkins.MavenCommand +import org.kie.jenkins.MavenStagingHelper deployProperties = [:] @@ -29,6 +30,7 @@ pipeline { KOGITO_CI_EMAIL_TO = credentials("${JENKINS_EMAIL_CREDS_ID}") PR_BRANCH_HASH = "${util.generateHash(10)}" + MAVEN_DEPLOY_LOCAL_DIR = "/tmp/maven_deploy_dir" } stages { @@ -100,24 +102,11 @@ pipeline { } } } - stage('Deploy kogito-apps') { + stage('Deploy kogito-apps locally') { steps { script { - withCredentials([usernamePassword(credentialsId: env.MAVEN_REPO_CREDS_ID, usernameVariable: 'REPOSITORY_USER', passwordVariable: 'REPOSITORY_TOKEN')]) { - def installOrDeploy - if (shouldDeployToRepository()) { - installOrDeploy = "deploy -DdeployAtEnd -Dapache.repository.username=${REPOSITORY_USER} -Dapache.repository.password=${REPOSITORY_TOKEN} -DretryFailedDeploymentCount=5" - } else { - installOrDeploy = 'install' - } - configFileProvider([configFile(fileId: env.MAVEN_SETTINGS_CONFIG_FILE_ID, variable: 'MAVEN_SETTINGS_FILE')]){ - getMavenCommand().withProperty('maven.test.failure.ignore', true) - .withOptions(env.BUILD_MVN_OPTS_CURRENT ? [ env.BUILD_MVN_OPTS_CURRENT ] : []) - .withOptions(env.KOGITO_APPS_BUILD_MVN_OPTS ? [ env.KOGITO_APPS_BUILD_MVN_OPTS ] : []) - .skipTests(skipTests) - .withSettingsXmlFile(MAVEN_SETTINGS_FILE) - .run("clean $installOrDeploy") - } + dir(getRepoName()){ + runMavenDeploy(params.SKIP_TESTS, true) } } } @@ -130,6 +119,30 @@ pipeline { } } } + stage('Upload artifacts to given repository') { + when { + expression { return !isRelease() && shouldDeployToRepository() } + } + steps { + script { + // Deploy to specific repository with credentials + maven.uploadLocalArtifacts(env.MAVEN_REPO_CREDS_ID, getLocalDeploymentFolder(), getMavenRepoZipUrl()) + } + } + } + stage('Stage artifacts') { + when { + expression { return shouldStageArtifacts() } + } + steps { + script { + dir(getRepoName()){ + // Stage release artifacts + runMavenStage() + } + } + } + } stage('Create PR') { when { expression { return isRelease() || isCreatePr() } @@ -211,6 +224,14 @@ void commitAndCreatePR() { deployProperties["${getRepoName()}.pr.link"] = githubscm.createPRWithLabels(commitMsg, prBody, getBuildBranch(), ['skip-ci'] as String[], getGitAuthorCredsId()) } +boolean isSpecificArtifactsUpload() { + return env.MAVEN_DEPLOY_REPOSITORY && env.MAVEN_REPO_CREDS_ID +} + +boolean shouldStageArtifacts() { + return isRelease() +} + boolean shouldDeployToRepository() { return env.MAVEN_DEPLOY_REPOSITORY && env.MAVEN_REPO_CREDS_ID && getGitAuthor() == 'apache' } @@ -254,12 +275,10 @@ void setDeployPropertyIfNeeded(String key, def value) { } } -MavenCommand getMavenCommand(String directory = '') { - directory = directory ?: getRepoName() +MavenCommand getMavenCommand() { return new MavenCommand(this, ['-fae', '-ntp']) - .withOptions(env.BUILD_MVN_OPTS ? [ env.BUILD_MVN_OPTS ] : []) - .inDirectory(directory) - .withProperty('full') + .withOptions(env.BUILD_MVN_OPTS ? [ env.BUILD_MVN_OPTS ] : []) + .withProperty('full') } void runMavenDeploy(boolean skipTests = true, boolean localDeployment = false) { @@ -271,20 +290,34 @@ void runMavenDeploy(boolean skipTests = true, boolean localDeployment = false) { mvnCmd.withDeployRepository(env.MAVEN_DEPLOY_REPOSITORY) } - withCredentials([usernamePassword(credentialsId: env.MAVEN_REPO_CREDS_ID, usernameVariable: 'REPOSITORY_USER', passwordVariable: 'REPOSITORY_TOKEN')]) { - def installOrDeploy - if (shouldDeployToRepository()) { - installOrDeploy = "deploy -DdeployAtEnd -Dapache.repository.username=${REPOSITORY_USER} -Dapache.repository.password=${REPOSITORY_TOKEN} -DretryFailedDeploymentCount=5" - } else { - installOrDeploy = 'install' - } - configFileProvider([configFile(fileId: env.MAVEN_SETTINGS_CONFIG_FILE_ID, variable: 'MAVEN_SETTINGS_FILE')]){ - mvnCmd.withProperty('maven.test.failure.ignore', true) - .withOptions(env.BUILD_MVN_OPTS_CURRENT ? [ env.BUILD_MVN_OPTS_CURRENT ] : []) - .withOptions(env.KOGITO_APPS_BUILD_MVN_OPTS ? [ env.KOGITO_APPS_BUILD_MVN_OPTS ] : []) - .skipTests(skipTests) - .withSettingsXmlFile(MAVEN_SETTINGS_FILE) - .run("clean $installOrDeploy") - } - } + configFileProvider([configFile(fileId: env.MAVEN_SETTINGS_CONFIG_FILE_ID, variable: 'MAVEN_SETTINGS_FILE')]){ + mvnCmd.withProperty('maven.test.failure.ignore', true) + .withOptions(env.BUILD_MVN_OPTS_CURRENT ? [ env.BUILD_MVN_OPTS_CURRENT ] : []) + .withOptions(env.KOGITO_APPS_BUILD_MVN_OPTS ? [ env.KOGITO_APPS_BUILD_MVN_OPTS ] : []) + .skipTests(skipTests) + .withSettingsXmlFile(MAVEN_SETTINGS_FILE) + .run('clean deploy') + } +} + +void runMavenStage() { + configFileProvider([configFile(fileId: env.MAVEN_SETTINGS_CONFIG_FILE_ID, variable: 'MAVEN_SETTINGS_FILE')]){ + MavenStagingHelper stagingHelper = getStagingHelper(getMavenCommand().withSettingsXmlFile(MAVEN_SETTINGS_FILE)) + deployProperties.putAll(stagingHelper.stageLocalArtifacts(env.NEXUS_STAGING_PROFILE_ID, getLocalDeploymentFolder())) + stagingHelper.promoteStagingRepository(env.NEXUS_BUILD_PROMOTION_PROFILE_ID) + } +} + +MavenStagingHelper getStagingHelper(MavenCommand mavenCommand) { + return new MavenStagingHelper(this, mavenCommand) + .withNexusReleaseUrl(env.NEXUS_RELEASE_URL) + .withNexusReleaseRepositoryId(env.NEXUS_RELEASE_REPOSITORY_ID) +} + +String getLocalDeploymentFolder() { + return "${env.MAVEN_DEPLOY_LOCAL_DIR}/${getRepoName()}" +} + +String getMavenRepoZipUrl() { + return "${env.MAVEN_DEPLOY_REPOSITORY.replaceAll('/content/', '/service/local/').replaceFirst('/*$', '')}/content-compressed" } diff --git a/.ci/jenkins/Jenkinsfile.weekly.deploy b/.ci/jenkins/Jenkinsfile.weekly.deploy index 05bda6c860..e446d1b504 100644 --- a/.ci/jenkins/Jenkinsfile.weekly.deploy +++ b/.ci/jenkins/Jenkinsfile.weekly.deploy @@ -71,25 +71,10 @@ pipeline { } } - stage('Build & Test & Install/Deploy') { + stage('Build & Test & Deploy locally') { steps { script { - withCredentials([usernamePassword(credentialsId: env.MAVEN_REPO_CREDS_ID, usernameVariable: 'REPOSITORY_USER', passwordVariable: 'REPOSITORY_TOKEN')]) { - def installOrDeploy - if (shouldDeployToRepository()) { - installOrDeploy = "deploy -DdeployAtEnd -Dapache.repository.username=${REPOSITORY_USER} -Dapache.repository.password=${REPOSITORY_TOKEN} -DretryFailedDeploymentCount=5" - } else { - installOrDeploy = 'install' - } - configFileProvider([configFile(fileId: env.MAVEN_SETTINGS_CONFIG_FILE_ID, variable: 'MAVEN_SETTINGS_FILE')]){ - getMavenCommand().withProperty('maven.test.failure.ignore', true) - .withOptions(env.BUILD_MVN_OPTS_CURRENT ? [ env.BUILD_MVN_OPTS_CURRENT ] : []) - .withOptions(env.KOGITO_APPS_BUILD_MVN_OPTS ? [ env.KOGITO_APPS_BUILD_MVN_OPTS ] : []) - .skipTests(params.SKIP_TESTS) - .withSettingsXmlFile(MAVEN_SETTINGS_FILE) - .run("clean $installOrDeploy") - } - } + runMavenLocalDeploy(params.SKIP_TESTS) } } post { @@ -102,6 +87,28 @@ pipeline { } } + stage('Upload artifacts to given repository') { + when { + expression { return shouldDeployToRepository() } + } + steps { + script { + withCredentials([usernamePassword(credentialsId: env.MAVEN_REPO_CREDS_ID, usernameVariable: 'REPOSITORY_USER', passwordVariable: 'REPOSITORY_TOKEN')]) { + configFileProvider([configFile(fileId: env.MAVEN_SETTINGS_CONFIG_FILE_ID, variable: 'MAVEN_SETTINGS_FILE')]) { + getMavenCommand() + .withSettingsXmlFile(MAVEN_SETTINGS_FILE) + .withProperty('wagon.source', "file://${getLocalDeploymentFolder()}") + .withProperty('wagon.target', env.MAVEN_DEPLOY_REPOSITORY) + .withProperty('wagon.targetId', 'apache-snapshots-repository') + .withProperty('apache.snapshot.repository.username', REPOSITORY_USER) + .withProperty('apache.snapshot.repository.password', REPOSITORY_TOKEN) + .run("org.codehaus.mojo:wagon-maven-plugin:2.0.2:merge-maven-repos") + } + } + } + } + } + stage('Create and push a new tag') { steps { script { diff --git a/.ci/jenkins/dsl/jobs.groovy b/.ci/jenkins/dsl/jobs.groovy index a1b3eb7e99..ecfefc4666 100644 --- a/.ci/jenkins/dsl/jobs.groovy +++ b/.ci/jenkins/dsl/jobs.groovy @@ -224,6 +224,11 @@ void setupReleaseDeployJob() { MAVEN_DEPENDENCIES_REPOSITORY: "${MAVEN_ARTIFACTS_REPOSITORY}", MAVEN_DEPLOY_REPOSITORY: "${MAVEN_ARTIFACTS_UPLOAD_REPOSITORY_URL}", MAVEN_REPO_CREDS_ID: "${MAVEN_ARTIFACTS_UPLOAD_REPOSITORY_CREDS_ID}", + + NEXUS_RELEASE_URL: "${MAVEN_NEXUS_RELEASE_URL}", + NEXUS_RELEASE_REPOSITORY_ID: "${MAVEN_NEXUS_RELEASE_REPOSITORY}", + NEXUS_STAGING_PROFILE_ID: "${MAVEN_NEXUS_STAGING_PROFILE_ID}", + NEXUS_BUILD_PROMOTION_PROFILE_ID: "${MAVEN_NEXUS_BUILD_PROMOTION_PROFILE_ID}", ]) KogitoJobTemplate.createPipelineJob(this, jobParams)?.with { parameters {