Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
Enabling Jenkins CD Configuration (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorhuol committed Mar 14, 2022
1 parent 585af99 commit 273b29d
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 349 deletions.
1 change: 1 addition & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_extends: .github
59 changes: 59 additions & 0 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Note: additional setup is required, see https://www.jenkins.io/redirect/continuous-delivery-of-plugins

name: cd
on:
workflow_dispatch:
check_run:
types:
- completed

jobs:
validate:
runs-on: ubuntu-latest
outputs:
should_release: ${{ steps.verify-ci-status.outputs.result == 'success' && steps.interesting-categories.outputs.interesting == 'true' }}
steps:
- name: Verify CI status
uses: jenkins-infra/verify-ci-status-action@v1.2.0
id: verify-ci-status
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
output_result: true

- name: Release Drafter
uses: release-drafter/release-drafter@v5
if: steps.verify-ci-status.outputs.result == 'success'
with:
name: next
tag: next
version: next
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Check interesting categories
uses: jenkins-infra/interesting-category-action@v1.0.0
id: interesting-categories
if: steps.verify-ci-status.outputs.result == 'success'
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

release:
runs-on: ubuntu-latest
needs: [validate]
if: needs.validate.outputs.should_release == 'true'
steps:
- name: Check out
uses: actions/checkout@v2.4.0
with:
fetch-depth: 0
- name: Set up JDK 8
uses: actions/setup-java@v3.0.0
with:
distribution: temurin
java-version: 8
- name: Release
uses: jenkins-infra/jenkins-maven-cd-action@v1.2.0
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_TOKEN: ${{ secrets.MAVEN_TOKEN }}
7 changes: 7 additions & 0 deletions .mvn/extensions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd">
<extension>
<groupId>io.jenkins.tools.incrementals</groupId>
<artifactId>git-changelist-maven-extension</artifactId>
<version>1.3</version>
</extension>
</extensions>
3 changes: 3 additions & 0 deletions .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-Pconsume-incrementals
-Pmight-produce-incrementals
-Dchangelist.format=%d.v%s
11 changes: 10 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,13 @@
* Includes the third-party code listed at http://links.sonatype.com/products/nexus/attributions.
* "Sonatype" is a trademark of Sonatype, Inc.
*/
buildPlugin()

// This Jenkins file is used by Jenkins CI and not by our internal Jenkins
buildPlugin(
useContainerAgent: true,
configurations: [
[ platform: "linux", jdk: "8" ],
[ platform: "windows", jdk: "8" ],
[ platform: "linux", jdk: "11" ],
[ platform: "windows", jdk: "11" ]
])
4 changes: 2 additions & 2 deletions Jenkinsfile.sonatype
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.sonatype.jenkins.pipeline.GitHub

String apiToken = null
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'integrations-github-api',
usernameVariable: 'GITHUB_API_USERNAME', passwordVariable: 'GITHUB_API_PASSWORD']]) {
usernameVariable: 'GITHUB_API_USERNAME', passwordVariable: 'GITHUB_API_PASSWORD']]) {
apiToken = env.GITHUB_API_PASSWORD
}

Expand All @@ -32,7 +32,7 @@ Closure postHandler = {
Closure iqPolicyEvaluation = {
stage ->
def commitId = getCommitId()
gitHub.statusUpdate commitId, 'pending', 'analysis', 'Nexus Lifecycle Analysis in running'
gitHub.statusUpdate commitId, 'pending', 'analysis', 'Nexus Lifecycle Analysis is running'

try {
def evaluation = nexusPolicyEvaluation failBuildOnNetworkError: false, iqApplication: 'nexus-platform-plugin',
Expand Down
82 changes: 0 additions & 82 deletions Jenkinsfile.sonatype.bump-up-api

This file was deleted.

117 changes: 117 additions & 0 deletions Jenkinsfile.sonatype.post-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Copyright (c) 2016-present Sonatype, Inc. All rights reserved.
* Includes the third-party code listed at http://links.sonatype.com/products/nexus/attributions.
* "Sonatype" is a trademark of Sonatype, Inc.
*/
@Library(['private-pipeline-library', 'jenkins-shared', 'int-jenkins-shared']) _
import com.sonatype.jenkins.pipeline.GitHub

String apiToken = null
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'integrations-github-api',
usernameVariable: 'GITHUB_API_USERNAME', passwordVariable: 'GITHUB_API_PASSWORD']]) {
apiToken = env.GITHUB_API_PASSWORD
}

GitHub gitHub = new GitHub(this, 'jenkinsci/nexus-platform-plugin', apiToken)

def jira = [
versionPrefix: 'jenkins', project: 'INT', projectId: '12410',
credentialId : 'jenkins-jira', autoRelease: true, failOnError: true
]

node('ubuntu-zion') {
String version, releaseNotes, branch
boolean addIQReleaseNotesLink

try {
stage('Preparation') {
deleteDir()

// Checkout and config
checkout scm
runSafely 'git config user.email sonatype-ci@sonatype.com'
runSafely 'git config user.name Sonatype CI'

// Setup common variables
version = params.pluginVersion
releaseNotes = params.releaseNotes
addIQReleaseNotesLink = params.addIQReleaseNotesLink
branch = 'main'

// Check mandatory parameters
if (!version) {
error 'The Plugin Version is a mandatory parameter!'
}

// Update display name
currentBuild.displayName = "#${currentBuild.number} - ${version}"
}
stage('Check plugin deployment') {
verifyDownloadLinks(
urlParts: ['https://repo.jenkins-ci.org/artifactory/releases/org/sonatype/nexus/ci/nexus-jenkins-plugin/',
version, '/nexus-jenkins-plugin-', version],
urlSuffixes: ['.hpi', '.pom', '.jar', '-sources.jar']
)
}
stage('Update and push code') {
// Check if want to update the change log
if(!releaseNotes && !addIQReleaseNotesLink) {
echo 'Skipping change log update'
return
}

// Update change logs
updateChangeLogs(releaseNotes, version, addIQReleaseNotesLink)

// Add and commit changes
runSafely 'git add README.md'
runSafely "git commit -m 'Updating change logs for release ${version}'"

// Push changes
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'integrations-github-api',
usernameVariable: 'GITHUB_API_USERNAME', passwordVariable: 'GITHUB_API_PASSWORD']]) {
// Setup remote url with credentials
runSafely "git remote set-url origin https://${env.GITHUB_API_USERNAME}:${env.GITHUB_API_PASSWORD}@github" +
'.com/jenkinsci/nexus-platform-plugin.git'

// Get latest commits to not have issues on push
runSafely "git pull --no-rebase --no-edit origin ${branch}"

// Push code changes
runSafely "git push origin HEAD:${branch}"
}
}
stage('Release Jira fix version') {
jiraSetFixVersion(jira, version)
}
}
finally {
postHandler(gitHub, currentBuild, env)
}
}

String getCommitId() {
return runSafely ('git rev-parse HEAD', true)
}

void postHandler(gitHub, currentBuild, env) {
def commitId = getCommitId()
if (currentBuild.currentResult == 'SUCCESS') {
gitHub.statusUpdate commitId, 'success', 'CI', 'Post Release Tasks Passed'
}
else {
gitHub.statusUpdate commitId, 'failure', 'CI', 'Post Release Tasks Failed'
}
}

void updateChangeLogs(releaseNotes, version, addIQReleaseNotesLink) {
def newDate = new Date().format( 'MMMM dd, yyyy' )
updateReleaseNotesMarkdown(
header: 'Changelog\n=========',
versionHeader: "${version} (${newDate})",
separator: '------------------------------------------------',
releaseNotes: releaseNotes,
filePath: 'README.md',
addIQReleaseNotesLink: addIQReleaseNotesLink
)
}

0 comments on commit 273b29d

Please sign in to comment.