121 lines
3.6 KiB
Groovy
121 lines
3.6 KiB
Groovy
#!/usr/bin/env groovy
|
|
|
|
def BRANCH_ENV = [
|
|
test: 'test',
|
|
master: 'production'
|
|
]
|
|
def remote = [:]
|
|
|
|
node {
|
|
stage('Setup') {
|
|
env.NODE_ENV = BRANCH_ENV[env.BRANCH_NAME] ?: 'dev'
|
|
|
|
echo "NODE_NAME: ${env.NODE_NAME}"
|
|
echo "WORKSPACE: ${env.WORKSPACE}"
|
|
}
|
|
}
|
|
pipeline {
|
|
agent any
|
|
environment {
|
|
PROJECT_NAME = 'hedera-web'
|
|
}
|
|
stages {
|
|
stage('Debuild') {
|
|
when {
|
|
anyOf {
|
|
branch 'master'
|
|
branch 'test'
|
|
}
|
|
}
|
|
agent {
|
|
docker {
|
|
image 'registry.verdnatura.es/debuild:2.23.4-vn4'
|
|
registryUrl 'https://registry.verdnatura.es/'
|
|
registryCredentialsId 'docker-registry'
|
|
args '-u root'
|
|
}
|
|
}
|
|
steps {
|
|
sh 'debuild -us -uc -b'
|
|
sh 'mkdir -p output'
|
|
sh 'cp ../*.deb output'
|
|
sh 'sleep 86400'
|
|
}
|
|
}
|
|
stage('Reprepro') {
|
|
when {
|
|
anyOf {
|
|
branch 'master'
|
|
branch 'test'
|
|
}
|
|
}
|
|
steps {
|
|
script {
|
|
remote.name = 'reprerpo'
|
|
remote.host = 'reprepro.reprepro'
|
|
remote.user = 'root'
|
|
remote.identityFile = '/home/jenkins/.ssh/id_ed25519'
|
|
remote.allowAnyHosts = true
|
|
}
|
|
sshPut([
|
|
remote: remote,
|
|
from: "$debFile",
|
|
into: '/tmp'
|
|
])
|
|
sshcommand([
|
|
remote: remote,
|
|
command: "sudo -u www-data reprepro -b /reprepro --gnupghome /reprepro/.gnupg includedeb bookworm /tmp/$debFile"
|
|
])
|
|
}
|
|
}
|
|
stage('Container') {
|
|
when {
|
|
anyOf {
|
|
branch 'master'
|
|
branch 'test'
|
|
}
|
|
}
|
|
environment {
|
|
CREDS = credentials('docker-registry')
|
|
}
|
|
steps {
|
|
script {
|
|
def packageJson = readJSON file: 'package.json'
|
|
env.VERSION = "${packageJson.version}-build${env.BUILD_ID}"
|
|
}
|
|
sh 'docker login --username $CREDS_USR --password $CREDS_PSW $REGISTRY'
|
|
sh 'docker-compose build --build-arg BUILD_ID=$BUILD_ID --parallel'
|
|
sh 'docker-compose push'
|
|
}
|
|
}
|
|
stage('Deploy') {
|
|
when {
|
|
anyOf {
|
|
branch 'master'
|
|
branch 'test'
|
|
}
|
|
}
|
|
steps {
|
|
script {
|
|
def packageJson = readJSON file: 'package.json'
|
|
env.VERSION = "${packageJson.version}-build${env.BUILD_ID}"
|
|
}
|
|
withKubeConfig([
|
|
serverUrl: "$KUBERNETES_API",
|
|
credentialsId: 'kubernetes',
|
|
namespace: 'salix'
|
|
]) {
|
|
sh 'kubectl set image deployment/hedera-web-$BRANCH_NAME hedera-web-$BRANCH_NAME=$REGISTRY/hedera-web:$VERSION'
|
|
sh 'kubectl set image deployment/hedera-web-cron-$BRANCH_NAME hedera-web-cron-$BRANCH_NAME=$REGISTRY/hedera-web:$VERSION'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
post {
|
|
unsuccessful {
|
|
setEnv()
|
|
sendEmail()
|
|
}
|
|
}
|
|
}
|