2018-05-31 12:34:34 +02:00
|
|
|
#!groovy
|
2018-07-12 11:06:54 +02:00
|
|
|
|
2020-03-11 15:36:59 +01:00
|
|
|
// switch back to a stable tag, after pr 22 is mreged an the next version is released
|
|
|
|
|
// see https://github.com/cloudogu/ces-build-lib/pull/22
|
2020-05-18 13:46:04 +02:00
|
|
|
@Library('github.com/cloudogu/ces-build-lib@7a14da6')
|
2018-05-31 12:34:34 +02:00
|
|
|
import com.cloudogu.ces.cesbuildlib.*
|
|
|
|
|
|
2018-09-24 13:04:03 +02:00
|
|
|
node('docker') {
|
2018-05-31 12:34:34 +02:00
|
|
|
|
2020-10-20 07:55:29 +02:00
|
|
|
developmentBranch = 'develop'
|
|
|
|
|
mainBranch = 'master'
|
2018-07-12 11:46:50 +02:00
|
|
|
|
2018-07-11 18:07:26 +02:00
|
|
|
properties([
|
|
|
|
|
// Keep only the last 10 build to preserve space
|
2018-09-21 09:07:12 +02:00
|
|
|
buildDiscarder(logRotator(numToKeepStr: '10')),
|
2020-03-11 11:05:54 +01:00
|
|
|
disableConcurrentBuilds()
|
2018-07-11 18:07:26 +02:00
|
|
|
])
|
2018-05-31 12:34:34 +02:00
|
|
|
|
2020-03-11 11:05:54 +01:00
|
|
|
timeout(activity: true, time: 60, unit: 'MINUTES') {
|
2018-05-31 12:34:34 +02:00
|
|
|
|
2020-03-06 12:02:34 +01:00
|
|
|
Git git = new Git(this)
|
2018-05-31 12:34:34 +02:00
|
|
|
|
2018-09-12 18:01:00 +02:00
|
|
|
catchError {
|
2018-05-31 12:34:34 +02:00
|
|
|
|
2018-09-12 18:01:00 +02:00
|
|
|
Maven mvn = setupMavenBuild()
|
2018-05-31 12:34:34 +02:00
|
|
|
|
2018-09-12 18:01:00 +02:00
|
|
|
stage('Checkout') {
|
|
|
|
|
checkout scm
|
|
|
|
|
}
|
2018-05-31 12:34:34 +02:00
|
|
|
|
2020-03-11 11:05:54 +01:00
|
|
|
if (isReleaseBranch()) {
|
|
|
|
|
stage('Set Version') {
|
|
|
|
|
String releaseVersion = getReleaseVersion();
|
|
|
|
|
// set maven versions
|
|
|
|
|
mvn "versions:set -DgenerateBackupPoms=false -DnewVersion=${releaseVersion}"
|
|
|
|
|
// set versions for ui packages
|
2020-03-12 10:36:13 +01:00
|
|
|
// we need to run 'yarn install' in order to set version with ui-scripts
|
2020-03-11 11:05:54 +01:00
|
|
|
mvn "-pl :scm-ui buildfrontend:install@install"
|
|
|
|
|
mvn "-pl :scm-ui buildfrontend:run@set-version"
|
|
|
|
|
|
|
|
|
|
// stage pom changes
|
|
|
|
|
sh "git status --porcelain | sed s/^...// | grep pom.xml | xargs git add"
|
|
|
|
|
// stage package.json changes
|
|
|
|
|
sh "git status --porcelain | sed s/^...// | grep package.json | xargs git add"
|
|
|
|
|
// stage lerna.json changes
|
|
|
|
|
sh "git add lerna.json"
|
|
|
|
|
|
|
|
|
|
// commit changes
|
|
|
|
|
sh "git -c user.name='CES Marvin' -c user.email='cesmarvin@cloudogu.com' commit -m 'release version ${releaseVersion}'"
|
|
|
|
|
|
2020-03-13 07:51:07 +01:00
|
|
|
// we need to fetch all branches, so we can checkout master and develop later
|
2020-03-26 18:43:00 +01:00
|
|
|
sh "git config 'remote.origin.fetch' '+refs/heads/*:refs/remotes/origin/*'"
|
2020-03-13 07:51:07 +01:00
|
|
|
sh "git fetch --all"
|
|
|
|
|
|
2020-10-16 11:40:56 +02:00
|
|
|
// merge release branch into main branch
|
|
|
|
|
sh "git checkout ${mainBranch}"
|
|
|
|
|
sh "git reset --hard origin/${mainBranch}"
|
2020-03-11 11:05:54 +01:00
|
|
|
sh "git merge --ff-only ${env.BRANCH_NAME}"
|
|
|
|
|
|
|
|
|
|
// set tag
|
|
|
|
|
sh "git -c user.name='CES Marvin' -c user.email='cesmarvin@cloudogu.com' tag -m 'release version ${releaseVersion}' ${releaseVersion}"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 18:01:00 +02:00
|
|
|
stage('Build') {
|
2020-05-26 13:11:33 +02:00
|
|
|
mvn "clean install -DskipTests"
|
2018-09-12 18:01:00 +02:00
|
|
|
}
|
2018-05-31 12:34:34 +02:00
|
|
|
|
2020-03-04 10:14:59 +01:00
|
|
|
parallel(
|
|
|
|
|
unitTest: {
|
|
|
|
|
stage('Unit Test') {
|
2020-05-27 12:26:11 +02:00
|
|
|
mvn 'test -DskipFrontendBuild -DskipTypecheck -Pcoverage -pl !scm-it -Dmaven.test.failure.ignore=true'
|
2020-03-13 08:06:34 +01:00
|
|
|
junit allowEmptyResults: true, testResults: '**/target/surefire-reports/TEST-*.xml,**/target/jest-reports/TEST-*.xml'
|
2020-03-04 10:14:59 +01:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
integrationTest: {
|
|
|
|
|
stage('Integration Test') {
|
|
|
|
|
mvn 'verify -Pit -DskipUnitTests -pl :scm-webapp,:scm-it -Dmaven.test.failure.ignore=true'
|
2020-08-25 11:17:05 +02:00
|
|
|
junit allowEmptyResults: true, testResults: '**/target/failsafe-reports/TEST-*.xml,**/target/cypress-reports/TEST-*.xml'
|
2020-08-25 10:31:40 +02:00
|
|
|
archiveArtifacts allowEmptyArchive: true, artifacts: 'scm-ui/e2e-tests/cypress/videos/*.mp4'
|
|
|
|
|
archiveArtifacts allowEmptyArchive: true, artifacts: 'scm-ui/e2e-tests/cypress/screenshots/**/*.png'
|
2020-03-04 10:14:59 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
2018-08-06 16:37:22 +02:00
|
|
|
|
2018-09-12 18:01:00 +02:00
|
|
|
stage('SonarQube') {
|
2020-05-12 13:05:30 +02:00
|
|
|
def sonarQube = new SonarCloud(this, [sonarQubeEnv: 'sonarcloud.io-scm', sonarOrganization: 'scm-manager', integrationBranch: 'develop'])
|
2020-05-10 21:44:13 +02:00
|
|
|
sonarQube.analyzeWith(mvn)
|
2018-07-11 18:07:26 +02:00
|
|
|
}
|
2018-09-24 13:03:02 +02:00
|
|
|
|
2020-10-16 11:40:56 +02:00
|
|
|
if (isBuildSuccessful() && (isDevelopmentBranch() || isReleaseBranch())) {
|
2020-05-10 21:47:35 +02:00
|
|
|
def commitHash = git.getCommitHash()
|
2019-01-30 11:25:01 +01:00
|
|
|
|
2020-05-10 21:47:35 +02:00
|
|
|
def imageVersion = mvn.getVersion()
|
|
|
|
|
if (imageVersion.endsWith('-SNAPSHOT')) {
|
|
|
|
|
imageVersion = imageVersion.replace('-SNAPSHOT', "-${commitHash.substring(0,7)}-${BUILD_NUMBER}")
|
2019-07-31 13:26:58 +02:00
|
|
|
}
|
2019-01-30 11:25:01 +01:00
|
|
|
|
2020-05-26 10:11:19 +02:00
|
|
|
stage('Deployment') {
|
2020-05-23 15:27:43 +02:00
|
|
|
// configuration for docker deployment
|
|
|
|
|
mvn.useRepositoryCredentials([
|
|
|
|
|
id: 'docker.io',
|
|
|
|
|
credentialsId: 'hub.docker.com-cesmarvin'
|
|
|
|
|
])
|
2020-05-10 21:47:35 +02:00
|
|
|
|
2020-06-03 14:41:03 +02:00
|
|
|
mvn.useRepositoryCredentials([
|
|
|
|
|
id: 'github.com/scm-manager/website',
|
|
|
|
|
credentialsId: 'cesmarvin-github'
|
|
|
|
|
])
|
|
|
|
|
|
2020-05-10 21:47:35 +02:00
|
|
|
// deploy java artifacts
|
2020-05-18 13:46:04 +02:00
|
|
|
mvn.useDeploymentRepository([
|
2020-05-23 15:27:43 +02:00
|
|
|
id: 'packages.scm-manager.org',
|
|
|
|
|
url: 'https://packages.scm-manager.org',
|
|
|
|
|
credentialsId: 'maven.scm-manager.org',
|
|
|
|
|
snapshotRepository: '/repository/snapshots/',
|
2020-05-18 13:46:04 +02:00
|
|
|
releaseRepository: '/repository/releases/',
|
|
|
|
|
type: 'Configurable'
|
|
|
|
|
])
|
2020-05-26 13:11:33 +02:00
|
|
|
mvn.deployToNexusRepository()
|
2020-05-10 21:47:35 +02:00
|
|
|
|
|
|
|
|
// deploy frontend bits
|
|
|
|
|
withCredentials([string(credentialsId: 'cesmarvin_npm_token', variable: 'NPM_TOKEN')]) {
|
|
|
|
|
writeFile encoding: 'UTF-8', file: '.npmrc', text: "//registry.npmjs.org/:_authToken='${NPM_TOKEN}'"
|
|
|
|
|
writeFile encoding: 'UTF-8', file: '.yarnrc', text: '''
|
|
|
|
|
registry "https://registry.npmjs.org/"
|
|
|
|
|
always-auth true
|
|
|
|
|
email cesmarvin@cloudogu.com
|
|
|
|
|
'''.trim()
|
|
|
|
|
|
|
|
|
|
// we are tricking lerna by pretending that we are not a git repository
|
|
|
|
|
sh "mv .git .git.disabled"
|
|
|
|
|
try {
|
|
|
|
|
mvn "-pl :scm-ui buildfrontend:run@deploy"
|
|
|
|
|
} finally {
|
|
|
|
|
sh "mv .git.disabled .git"
|
2020-03-11 11:05:54 +01:00
|
|
|
}
|
|
|
|
|
}
|
2020-05-25 15:11:21 +02:00
|
|
|
|
|
|
|
|
// deploy packages
|
2020-05-26 09:47:38 +02:00
|
|
|
withGPGEnvironment {
|
2020-05-26 13:18:59 +02:00
|
|
|
mvn "-Dgpg.scm.keyring='${GPG_KEYRING}' -Dgpg.scm.key='${GPG_KEY_ID}' -Dgpg.scm.passphrase='${GPG_KEY_PASSPHRASE}' -Ppackaging -rf :scm-packaging deploy"
|
2020-05-26 09:47:38 +02:00
|
|
|
}
|
2020-05-10 21:47:35 +02:00
|
|
|
}
|
2020-03-11 11:05:54 +01:00
|
|
|
|
2020-05-25 13:53:44 +02:00
|
|
|
stage('Presentation Environment') {
|
2020-10-16 11:40:56 +02:00
|
|
|
// we don't use developmentBranch, because we only want the lastest version of develop branch on
|
|
|
|
|
// next-scm. We don't want a support branch or something similar on the presentation environment.
|
|
|
|
|
if ("develop".equals(env.BRANCH_NAME)) {
|
|
|
|
|
build job: 'scm-manager/next-scm.cloudogu.com', propagate: false, wait: false, parameters: [
|
|
|
|
|
string(name: 'changeset', value: commitHash),
|
|
|
|
|
string(name: 'imageTag', value: imageVersion)
|
|
|
|
|
]
|
|
|
|
|
}
|
2020-05-25 13:53:44 +02:00
|
|
|
}
|
2020-03-11 11:05:54 +01:00
|
|
|
|
2020-05-10 21:47:35 +02:00
|
|
|
if (isReleaseBranch()) {
|
|
|
|
|
stage('Update Repository') {
|
|
|
|
|
|
|
|
|
|
// merge changes into develop
|
2020-10-16 11:40:56 +02:00
|
|
|
sh "git checkout ${developmentBranch}"
|
|
|
|
|
|
2020-05-10 21:47:35 +02:00
|
|
|
// TODO what if we have a conflict
|
|
|
|
|
// e.g.: someone has edited the changelog during the release
|
2020-10-16 11:40:56 +02:00
|
|
|
if (!developmentBranch.equals(mainBranch)) {
|
|
|
|
|
sh "git merge ${mainBranch}"
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-10 21:47:35 +02:00
|
|
|
|
|
|
|
|
// set versions for maven packages
|
|
|
|
|
mvn "build-helper:parse-version versions:set -DgenerateBackupPoms=false -DnewVersion='\${parsedVersion.majorVersion}.\${parsedVersion.nextMinorVersion}.0-SNAPSHOT'"
|
2020-03-11 11:05:54 +01:00
|
|
|
|
2020-05-10 21:47:35 +02:00
|
|
|
// set versions for ui packages
|
|
|
|
|
mvn "-pl :scm-ui buildfrontend:run@set-version"
|
|
|
|
|
|
|
|
|
|
// stage pom changes
|
|
|
|
|
sh "git status --porcelain | sed s/^...// | grep pom.xml | xargs git add"
|
|
|
|
|
// stage package.json changes
|
|
|
|
|
sh "git status --porcelain | sed s/^...// | grep package.json | xargs git add"
|
|
|
|
|
// stage lerna.json changes
|
|
|
|
|
sh "git add lerna.json"
|
|
|
|
|
|
|
|
|
|
// commit changes
|
|
|
|
|
sh "git -c user.name='CES Marvin' -c user.email='cesmarvin@cloudogu.com' commit -m 'prepare for next development iteration'"
|
|
|
|
|
|
|
|
|
|
// push changes back to remote repository
|
|
|
|
|
withCredentials([usernamePassword(credentialsId: 'cesmarvin-github', usernameVariable: 'GIT_AUTH_USR', passwordVariable: 'GIT_AUTH_PSW')]) {
|
2020-10-16 11:40:56 +02:00
|
|
|
sh "git -c credential.helper=\"!f() { echo username='\$GIT_AUTH_USR'; echo password='\$GIT_AUTH_PSW'; }; f\" push origin ${mainBranch} --tags"
|
|
|
|
|
if (!developmentBranch.equals(mainBranch)) {
|
|
|
|
|
sh "git -c credential.helper=\"!f() { echo username='\$GIT_AUTH_USR'; echo password='\$GIT_AUTH_PSW'; }; f\" push origin develop --tags"
|
|
|
|
|
}
|
2020-05-10 21:47:35 +02:00
|
|
|
sh "git -c credential.helper=\"!f() { echo username='\$GIT_AUTH_USR'; echo password='\$GIT_AUTH_PSW'; }; f\" push origin :${env.BRANCH_NAME}"
|
2019-08-06 11:32:05 +02:00
|
|
|
}
|
2018-09-25 09:22:25 +02:00
|
|
|
}
|
|
|
|
|
}
|
2018-09-24 17:13:47 +02:00
|
|
|
}
|
2018-05-31 12:34:34 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-06 12:02:34 +01:00
|
|
|
mailIfStatusChanged(git.commitAuthorEmail)
|
2018-09-12 18:01:00 +02:00
|
|
|
}
|
2018-05-31 12:34:34 +02:00
|
|
|
}
|
2018-07-11 18:23:49 +02:00
|
|
|
|
2020-10-16 11:40:56 +02:00
|
|
|
String developmentBranch
|
2018-07-12 11:46:50 +02:00
|
|
|
String mainBranch
|
2018-07-12 10:55:03 +02:00
|
|
|
|
2018-07-12 11:15:24 +02:00
|
|
|
Maven setupMavenBuild() {
|
2020-12-18 14:23:36 +01:00
|
|
|
MavenWrapperInDocker mvn = new MavenWrapperInDocker(this, "scmmanager/java-build:11.0.9_11.1")
|
2020-05-10 21:18:51 +02:00
|
|
|
mvn.enableDockerHost = true
|
|
|
|
|
|
2020-03-04 12:12:57 +01:00
|
|
|
// disable logging durring the build
|
2020-03-04 12:56:38 +01:00
|
|
|
def logConf = "scm-webapp/src/main/resources/logback.ci.xml"
|
|
|
|
|
mvn.additionalArgs += " -Dlogback.configurationFile=${logConf}"
|
|
|
|
|
mvn.additionalArgs += " -Dscm-it.logbackConfiguration=${logConf}"
|
2020-05-19 10:48:04 +02:00
|
|
|
mvn.additionalArgs += " -Dsonar.coverage.exclusions=**/*.test.ts,**/*.test.tsx,**/*.stories.tsx"
|
2018-07-12 11:15:24 +02:00
|
|
|
|
2020-10-16 11:40:56 +02:00
|
|
|
if (isDevelopmentBranch() || isReleaseBranch()) {
|
2018-07-12 11:15:24 +02:00
|
|
|
// Release starts javadoc, which takes very long, so do only for certain branches
|
|
|
|
|
mvn.additionalArgs += ' -DperformRelease'
|
|
|
|
|
// JDK8 is more strict, we should fix this before the next release. Right now, this is just not the focus, yet.
|
|
|
|
|
mvn.additionalArgs += ' -Dmaven.javadoc.failOnError=false'
|
|
|
|
|
}
|
|
|
|
|
return mvn
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-11 11:05:54 +01:00
|
|
|
boolean isReleaseBranch() {
|
|
|
|
|
return env.BRANCH_NAME.startsWith("release/");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getReleaseVersion() {
|
|
|
|
|
return env.BRANCH_NAME.substring("release/".length());
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-16 11:40:56 +02:00
|
|
|
boolean isDevelopmentBranch() {
|
|
|
|
|
return developmentBranch.equals(env.BRANCH_NAME)
|
2018-09-25 09:22:25 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-26 09:47:38 +02:00
|
|
|
void withGPGEnvironment(def closure) {
|
|
|
|
|
withCredentials([
|
|
|
|
|
file(credentialsId: 'oss-gpg-secring', variable: 'GPG_KEYRING'),
|
|
|
|
|
usernamePassword(credentialsId: 'oss-keyid-and-passphrase', usernameVariable: 'GPG_KEY_ID', passwordVariable: 'GPG_KEY_PASSPHRASE')
|
|
|
|
|
]) {
|
|
|
|
|
closure.call()
|
|
|
|
|
}
|
|
|
|
|
}
|