Skip to content

Commit

Permalink
Feature/flexible r2p jira workflow (#923)
Browse files Browse the repository at this point in the history
* Developer preview uses the release branch if exists, the branch in Release Manager's metadata.yml cfg if not. (#917)

* changelog

* Logging we need to see what is going on.

* Small refactor to clarify what source code does.

* Use release branch if it exists, in dev mode.

* Checkout release branch for developer preview if available.

Co-authored-by: Victor Pablos Ceruelo <victor.pablos_ceruelo.ext@boehringer-ingelheim.com>

* Feature/edpc 1323 dev preview from release branch if exists (#920)

* changelog

* Logging we need to see what is going on.

* Small refactor to clarify what source code does.

* Use release branch if it exists, in dev mode.

* Checkout release branch for developer preview if available.

* Log in debug mode undone jira issues and chapters.

* Log in debug mode comment added to Jira Release Status

* Do branch checkout for non-release repos too-.

* gitReleaseBranch id needs to be saved for future usage in pipeline.

* If release manager branch is master, other comp. branch is defined in yaml.

* Need to push to the branch we are looking for.

* Initialize map before using it.

* typo

* Tests for InitStage

* tests for MROPipelineUtil.

* changelog

Co-authored-by: Victor Pablos Ceruelo <victor.pablos_ceruelo.ext@boehringer-ingelheim.com>

* Removes DIL_P doc. (#914)

* Removes DIL_P doc.

* Trying to log what is being sent to jira

* Correct way to log variable.

* Pretty print map using json format.

* Revert "Correct way to log variable."

This reverts commit 8ae309a.

* Revert "Trying to log what is being sent to jira"

This reverts commit 0367847.

* jcenter is no more available.

* Removes from test checking that DIL_P is generated.

* changelog

Co-authored-by: zxBCN Pablos_Ceruelo,Victor (IT EDS) EXTERNAL <victor.pablos_ceruelo.ext@boehringer-ingelheim.com>

* Sets rePromote field to true by default + tests.

* Check if tag exists.

* Fixes tests readability.

* Need to eval locally if tag exists before creating it.

* edpc 1323 dev preview from release branch if exists (#925)

* changelog

* Logging we need to see what is going on.

* Small refactor to clarify what source code does.

* Use release branch if it exists, in dev mode.

* Checkout release branch for developer preview if available.

* Log in debug mode undone jira issues and chapters.

* Log in debug mode comment added to Jira Release Status

* Do branch checkout for non-release repos too-.

* gitReleaseBranch id needs to be saved for future usage in pipeline.

* If release manager branch is master, other comp. branch is defined in yaml.

* Need to push to the branch we are looking for.

* Initialize map before using it.

* typo

* Tests for InitStage

* tests for MROPipelineUtil.

* changelog

* Reverts problematic change.

Co-authored-by: Victor Pablos Ceruelo <victor.pablos_ceruelo.ext@boehringer-ingelheim.com>

* Feature/edpc 1335 allow to redeploy in D, Q and P (#926)

* Sets rePromote field to true by default + tests.

* Check if tag exists.

* Fixes tests readability.

* Need to eval locally if tag exists before creating it.

* changelog

Co-authored-by: zxBCN Pablos_Ceruelo,Victor (IT EDS) EXTERNAL <victor.pablos_ceruelo.ext@boehringer-ingelheim.com>

* changelog

* Feature/edpc 1335 set repromote to true if unset (#927)

* Sets rePromote field to true by default + tests.

* Check if tag exists.

* Fixes tests readability.

* Need to eval locally if tag exists before creating it.

* changelog

Co-authored-by: zxBCN Pablos_Ceruelo,Victor (IT EDS) EXTERNAL <victor.pablos_ceruelo.ext@boehringer-ingelheim.com>
Co-authored-by: Martinez,Angel (IT EDS) BI-ES-S <angel_2.martinez@boehringer-ingelheim.com>

* Force push in RM tags with redeploy

Co-authored-by: Victor Pablos Ceruelo <victor.pablos_ceruelo.ext@boehringer-ingelheim.com>
Co-authored-by: Martinez,Angel (IT EDS) BI-ES-S <angel_2.martinez@boehringer-ingelheim.com>
Co-authored-by: Jorge Romero <jorge.romeropalma@gmail.com>
Co-authored-by: Rodriguez,Hector (IT EDS) <hector_2.rodriguez@boehringer-ingelheim.com>
  • Loading branch information
5 people authored Aug 16, 2022
1 parent ad8e11e commit a4e1bbd
Show file tree
Hide file tree
Showing 14 changed files with 380 additions and 115 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
- Added default timeout to Aqua stage ([#899](https://github.com/opendevstack/ods-jenkins-shared-library/issues/899))
- Increase default timeout for rollout ([#903](https://github.com/opendevstack/ods-jenkins-shared-library/issues/903))
- Add retry for Openshift image build status ([#901](https://github.com/opendevstack/ods-jenkins-shared-library/issues/901))
- Removes DIL from the set of docs generated for enviroment P ([914](https://github.com/opendevstack/ods-jenkins-shared-library/pull/914))
- Developer preview uses the release branch if exists, the branch in Release Manager s metadata.yml cfg if not ([#920](https://github.com/opendevstack/ods-jenkins-shared-library/pull/920/))
- Allow to redeploy to D, Q and P, by setting repromote to true by default and creating tags only if they do not exist ([#926](https://github.com/opendevstack/ods-jenkins-shared-library/pull/926))
- fix Aqua integration fails for future versions ([#875](https://github.com/opendevstack/ods-jenkins-shared-library/issues/875))
- fix nexus pypi upload ([#812](https://github.com/opendevstack/ods-jenkins-shared-library/issues/812))
- Fix return image build info in odsComponentStageBuildOpenShiftImage ([#909](https://github.com/opendevstack/ods-jenkins-shared-library/issues/909))
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repositories {
if (no_nexus) {
println("using repositories 'jcenter' and 'mavenCentral'")
mavenLocal()
jcenter()
// deprecated: jcenter()
mavenCentral()
maven {
url "https://repo1.maven.org/maven2/"
Expand Down Expand Up @@ -46,7 +46,7 @@ repositories {
url repoUrl
}
}
nexusMaven("${nexus_url}/repository/jcenter/")
// deprecated: nexusMaven("${nexus_url}/repository/jcenter/")
nexusMaven("${nexus_url}/repository/maven-public/")
nexusMaven("${nexus_url}/repository/atlassian_public/")
nexusMaven("${nexus_url}/repository/jenkins-ci-releases/")
Expand Down Expand Up @@ -82,7 +82,7 @@ dependencies {
testImplementation ("com.athaydes:spock-reports:1.6.3") { transitive = false }
testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.21.0'
testImplementation group: 'commons-io', name: 'commons-io', version: '2.8.0'
testImplementation "com.lesfurets:jenkins-pipeline-unit:1.9"
testImplementation group: 'com.lesfurets', name: 'jenkins-pipeline-unit', version: '1.9' // "com.lesfurets:jenkins-pipeline-unit:1.9"
testImplementation "net.bytebuddy:byte-buddy:1.10.8"
testImplementation "org.objenesis:objenesis:3.1"
testImplementation "cglib:cglib-nodep:3.3.0" // for mocking classes
Expand Down
28 changes: 19 additions & 9 deletions src/org/ods/orchestration/FinalizeStage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ class FinalizeStage extends Stage {
logger.debug("Gathering commits")
gatherCreatedExecutionCommits(steps, git)

if (!project.buildParams.rePromote) {
pushRepos(steps, git)
recordAndPushEnvStateForReleaseManager(steps, logger, git)
}
pushRepos(steps, git)
recordAndPushEnvStateForReleaseManager(steps, logger, git)

// add the tag commit that was created for traceability ..
logger.debug "Current release manager commit: ${project.gitData.commit}"
Expand All @@ -98,6 +96,9 @@ class FinalizeStage extends Stage {

levaDocScheduler.run(phase, PipelinePhaseLifecycleStage.PRE_END)

logger.debug("Project has failing tests? ${project.hasFailingTests()}")
logger.debug("Project has unexecuted jira tests? ${project.hasUnexecutedJiraTests()}")

// Fail the build in case of failing tests.
if (project.hasFailingTests() || project.hasUnexecutedJiraTests()) {
def message = 'Error: '
Expand All @@ -124,6 +125,7 @@ class FinalizeStage extends Stage {
util.failBuild(message)
throw new IllegalStateException(message)
} else {
logger.debug("Reporting pipeline status to Jira...")
project.reportPipelineStatus()
if (!project.isWorkInProgress) {
bitbucket.setBuildStatus (steps.env.BUILD_URL, project.gitData.commit,
Expand All @@ -141,12 +143,17 @@ class FinalizeStage extends Stage {
repoPushTasks << [ (repo.id): {
steps.dir("${steps.env.WORKSPACE}/${MROPipelineUtil.REPOS_BASE_DIR}/${repo.id}") {
if (project.isWorkInProgress) {
git.pushRef(repo.branch)
String branchName = repo.data.git.branch ?: repo.branch
git.pushRef(branchName)
} else if (project.isAssembleMode) {
git.createTag(project.targetTag)
if (!git.remoteTagExists(project.targetTag)) {
git.createTag(project.targetTag)
}
git.pushBranchWithTags(project.gitReleaseBranch)
} else {
git.createTag(project.targetTag)
if (!git.remoteTagExists(project.targetTag)) {
git.createTag(project.targetTag)
}
git.pushRef(project.targetTag)
}
}
Expand Down Expand Up @@ -255,8 +262,11 @@ class FinalizeStage extends Stage {
)
git.pushRef(MASTER_BRANCH)
git.switchToExistingBranch(project.gitReleaseBranch)
git.createTag(project.targetTag)
git.pushBranchWithTags(project.gitReleaseBranch)
if (!git.remoteTagExists(project.targetTag)) {
git.createTag(project.targetTag)
}
// To overwrite the existing tag (if redeploy)
git.pushForceBranchWithTags(project.gitReleaseBranch)
}
}

Expand Down
60 changes: 43 additions & 17 deletions src/org/ods/orchestration/InitStage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,7 @@ class InitStage extends Stage {
// to concurrent releases).
def envState = loadEnvState(logger, buildParams.targetEnvironment)

logger.startClocked("git-releasemanager-${STAGE_NAME}")
// git checkout
def gitReleaseBranch = GitService.getReleaseBranch(buildParams.version)
if (!Project.isWorkInProgress(buildParams.version)) {
if (Project.isPromotionMode(buildParams.targetEnvironmentToken)) {
checkOutRepoInPromotionMode(git, buildParams, logger, gitReleaseBranch)
} else {
checkOutRepoInNotPromotionMode(git, gitReleaseBranch, logger)
}
}
logger.debugClocked("git-releasemanager-${STAGE_NAME}")
checkOutReleaseManagerRepository(buildParams, git, logger)

logger.debug 'Load build params and metadata file information'
project.init()
Expand Down Expand Up @@ -145,7 +135,7 @@ class InitStage extends Stage {
return stageToStartAgent
}

private Closure buildCheckOutClousure(repos, logger, envState, util) {
private Closure buildCheckOutClousure(repos, logger, envState, MROPipelineUtil util) {
@SuppressWarnings('Indentation')
Closure checkoutClosure =
{
Expand Down Expand Up @@ -440,23 +430,59 @@ class InitStage extends Stage {
}
}

private void checkOutRepoInNotPromotionMode(GitService git, String gitReleaseBranch, Logger logger) {
private void checkOutReleaseManagerRepository(def buildParams, def git,
ILogger logger) {
logger.startClocked("git-releasemanager-${STAGE_NAME}")
if (!Project.isWorkInProgress(buildParams.version)) {
def gitReleaseBranch = GitService.getReleaseBranch(buildParams.version)
logger.debug("Release Manager branch to checkout: ${gitReleaseBranch}")
if (Project.isPromotionMode(buildParams.targetEnvironmentToken)) {
checkOutRepoInPromotionMode(git, buildParams, gitReleaseBranch, logger)
} else {
checkOutRepoInNotPromotionMode(git, gitReleaseBranch, false, logger)
}
} else {
// Here is the difference with respect to deploy-to-D:
// The branch to be used is obtained from buildParams.changeId, not from buildParams.version ( = WIP ).
def gitReleaseBranch = GitService.getReleaseBranch(buildParams.changeId)
logger.info("Release branch that should be used if available: ${gitReleaseBranch}")
checkOutRepoInNotPromotionMode(git, gitReleaseBranch, true, logger)
}
logger.debugClocked("git-releasemanager-${STAGE_NAME}")

}

private void checkOutRepoInNotPromotionMode(GitService git,
String gitReleaseBranch,
boolean isWorkInProgress,
Logger logger) {
if (git.remoteBranchExists(gitReleaseBranch)) {
logger.info("Checkout release manager repository @ ${gitReleaseBranch}")
logger.info("Checkout release manager repository branch ${gitReleaseBranch}")
git.checkout(
"*/${gitReleaseBranch}",
[[$class: 'LocalBranch', localBranch: gitReleaseBranch]],
script.scm.userRemoteConfigs
)
project.setGitReleaseBranch(gitReleaseBranch)
} else {
git.checkoutNewLocalBranch(gitReleaseBranch)
// If we are still in WIP and there is no branch for current release,
// do not create it. We use if only if it exists. We use master if it does not exist.
if (! isWorkInProgress) {
logger.info("Creating release manager repository branch: ${gitReleaseBranch}")
git.checkoutNewLocalBranch(gitReleaseBranch)
project.setGitReleaseBranch(gitReleaseBranch)
} else {
logger.info("Since no deploy was done to D (branch ${gitReleaseBranch} does not exist), "+
"using master branch for developer preview.")
project.setGitReleaseBranch("master")
}
}
}

private void checkOutRepoInPromotionMode(GitService git,
Map buildParams,
Logger logger,
String gitReleaseBranch) {
String gitReleaseBranch,
Logger logger) {
def tagList = git.readBaseTagList(
buildParams.version,
buildParams.changeId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ class LeVADocumentScheduler extends DocGenScheduler {
(DocumentType.TIR as String) : ["${DocumentType.TIR}_P"],
(DocumentType.OVERALL_TIR as String) : ["${DocumentType.TIR}_P"],
(DocumentType.IVR as String) : ["${DocumentType.IVR}_P"],
(DocumentType.OVERALL_IVR as String) : ["${DocumentType.IVR}_P"],
(DocumentType.DIL as String) : ["${DocumentType.DIL}_P"]
(DocumentType.OVERALL_IVR as String) : ["${DocumentType.IVR}_P"]
]
]

Expand Down
5 changes: 4 additions & 1 deletion src/org/ods/orchestration/usecase/JiraUseCase.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,10 @@ class JiraUseCase {
}

void updateJiraReleaseStatusResult(String message, boolean isError) {
if (!this.jira) return
if (!this.jira) {
logger.warn("JiraUseCase: jira has an invalid value.")
return
}

def status = isError ? 'Failed' : 'Successful'

Expand Down
Loading

0 comments on commit a4e1bbd

Please sign in to comment.