88 lines
2.7 KiB
Groovy
88 lines
2.7 KiB
Groovy
import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
|
|
|
|
node {
|
|
|
|
cleanWs();
|
|
|
|
stage("checkout") {
|
|
checkout scm
|
|
}
|
|
|
|
docker.withRegistry("https://docker.romanjaros.cz") {
|
|
docker.image("romanjaros/ci-nodejs:10.x").inside("-v /usr/bin/git:/usr/bin/git") {
|
|
stage("install") {
|
|
sh "cp .npmrc ~/.npmrc"
|
|
sh "npm install"
|
|
sh "npm run bootstrap"
|
|
}
|
|
stage("code check") {
|
|
sh "npm run lint"
|
|
sh "npm run test"
|
|
}
|
|
stage("build") {
|
|
sh "npm run build"
|
|
}
|
|
stage("release") {
|
|
if (env.BRANCH_NAME.startsWith("release/") && !isReleaseCommit()) {
|
|
withCredentials([usernamePassword(
|
|
credentialsId: 'jenkins',
|
|
usernameVariable: 'GIT_USERNAME',
|
|
passwordVariable: 'GIT_PASSWORD'
|
|
)]) {
|
|
setGitConfig()
|
|
sh "git config credential.username $GIT_USERNAME"
|
|
sh "git config credential.helper '!echo password=$GIT_PASSWORD; echo'"
|
|
}
|
|
sh "git checkout ${env.BRANCH_NAME}"
|
|
def setVersion = getReleaseVersionType()
|
|
sh "npx lerna version ${setVersion} --no-git-tag-version --no-push --yes"
|
|
def newVersion = getPackageJsonVersion();
|
|
sh "git status"
|
|
sh "git commit -am 'RELEASE;New version $newVersion'"
|
|
sh "git log -1 --oneline"
|
|
sh "npx lerna exec --ignore documentation -- 'cp package.json src && cd src/ && npm publish && rm package.json'"
|
|
sh "git push -u origin ${env.BRANCH_NAME} --force"
|
|
} else {
|
|
Utils.markStageSkippedForConditional("release:version")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
stage("deploy:test") {
|
|
if (env.BRANCH_NAME == "develop") {
|
|
sh "docker build -t jenkins/treejs:latest -f docker/Dockerfile ."
|
|
sh "docker image prune -f"
|
|
stopAndRemoveDockerImages();
|
|
sh "docker run --name treejs_client -d -p 83:80 -e APP_ENV=test --entrypoint='nginx' jenkins/treejs:latest -g 'daemon off;'"
|
|
} else {
|
|
Utils.markStageSkippedForConditional("deploy:test")
|
|
}
|
|
}
|
|
}
|
|
|
|
def isReleaseCommit() {
|
|
return getLastCommitMessage().startsWith("RELEASE;New")
|
|
}
|
|
|
|
def stopAndRemoveDockerImages() {
|
|
sh "docker stop treejs_client || true && docker rm treejs_client || true"
|
|
}
|
|
|
|
def getLastCommitMessage() {
|
|
return sh(returnStdout: true, script: 'git log -1 --pretty=format:%s').trim()
|
|
}
|
|
|
|
def setGitConfig() {
|
|
sh "git config --global user.email 'jenkins@romanjaros.cz'";
|
|
sh "git config --global user.name 'Jenkins'";
|
|
}
|
|
|
|
def getReleaseVersionType() {
|
|
return env.BRANCH_NAME.tokenize("/").getAt(1)
|
|
}
|
|
|
|
def getPackageJsonVersion() {
|
|
def packageJson = readJSON file: 'modules/documentation/package.json'
|
|
return packageJson.version;
|
|
}
|