CureNet/Jenkinsfile

197 lines
4.9 KiB
Groovy

pipeline {
agent any
environment {
DatabaseUrl = sh(returnStdout: true, script: 'bash /var/lib/jenkins/variables/CureNet/var.sh ${BRANCH_NAME} DatabaseUrl').trim()
DatabaseUrlTesting = sh(returnStdout: true, script: 'bash /var/lib/jenkins/variables/CureNet/var.sh test DatabaseUrl').trim()
}
stages {
stage('Pull') {
steps {
git(url: 'http://git.fufle.net/Community/CureNet.git', branch: '${BRANCH_NAME}', credentialsId: '799188a2-c281-4e4c-b78f-c82132ea792b', poll: true)
}
}
stage('Approve') {
steps {
echo "http://git.fufle.net/Community/CureNet/commit/${env.GIT_COMMIT}"
script {
if (env.BRANCH_NAME == "prod") {
echo "http://git.fufle.net/Community/CureNet/compare/prod...staging"
input(message: 'Deploy to production?', id: 'A', ok: 'Yes', submitter: 'deploy', submitterParameter: 'a')
}
if (env.BRANCH_NAME == "staging") {
echo "http://git.fufle.net/Community/CureNet/compare/staging...beta"
input(message: 'Deploy to staging instance?', id: 'A', ok: 'Yes', submitter: 'deploy', submitterParameter: 'a')
}
if (env.BRANCH_NAME == "beta") {
echo "http://git.fufle.net/Community/CureNet/compare/beta...dev"
input(message: 'Deploy to beta instance?', id: 'A', ok: 'Yes', submitter: 'deploy', submitterParameter: 'a')
}
}
}
}
stage('Install') {
parallel {
stage('Frontend') {
steps {
dir(path: 'src/frontend') {
sh 'sed -i "s/-1001/${BUILD_ID}/g" src/environments/*.ts'
sh 'Timestamp=`php8.0 -r "echo time();"` && sed -i "s/-1002/${Timestamp}/g" src/environments/*.ts'
sh 'npm ci'
}
}
}
stage('Backend') {
steps {
dir(path: 'src/backend') {
sh 'php8.0 /bin/composer install'
}
}
}
}
}
stage('Configure for tests') {
parallel {
stage('Frontend') {
steps {
dir(path: 'src/frontend') {
sh 'echo skip'
}
}
}
stage('Backend') {
steps {
dir(path: 'src/backend') {
sh 'APP_SECRET=`php8.0 -r "echo md5(\\"branch=${BRANCH_NAME};\\");"` && sed -i "s/APP_SECRET=.*/APP_SECRET=${APP_SECRET}/g" .env'
sh 'sed -i "s/DATABASE_URL=.*/DATABASE_URL=${DatabaseUrlTesting}/g" .env.test'
sh 'composer dump-env test'
sh 'php8.0 bin/console doctrine:schema:update --force';
}
}
}
}
}
stage('Test') {
parallel {
stage('Frontend') {
steps {
dir(path: 'src/frontend') {
sh 'ng lint'
}
}
}
stage('Backend') {
steps {
dir(path: 'src/backend') {
sh 'php8.0 vendor/bin/phpunit'
}
}
}
}
}
stage('Configure') {
parallel {
stage('Frontend') {
steps {
dir(path: 'src/frontend') {
sh 'echo skip'
}
}
}
stage('Backend') {
steps {
dir(path: 'src/backend') {
sh 'APP_SECRET=`php8.0 -r "echo md5(\\"branch=${BRANCH_NAME};\\");"` && sed -i "s/APP_SECRET=.*/APP_SECRET=${APP_SECRET}/g" .env'
sh 'sed -i "s/DATABASE_URL=.*/DATABASE_URL=${DatabaseUrl}/g" .env.dev'
sh 'composer dump-env dev'
}
}
}
}
}
stage('Build') {
parallel {
stage('Frontend') {
steps {
dir(path: 'src/frontend') {
sh 'ng b -c production'
}
}
}
stage('Backend') {
steps {
dir(path: 'src/backend') {
sh 'echo skip'
}
}
}
}
}
stage('Deploy') {
when {
anyOf {
branch 'prod'
branch 'staging'
branch 'beta'
branch 'dev'
}
}
parallel {
stage('Frontend') {
steps {
dir(path: 'src/frontend') {
sh 'ssh web@fufle.net touch /web/fufle.net/curenet/dev/frontend/REMOVEME'
sh 'ssh web@fufle.net rm -rf /web/fufle.net/curenet/dev/frontend/*'
sh 'scp -r dist/* web@fufle.net:/web/fufle.net/curenet/dev/frontend/'
}
}
}
stage('Backend') {
steps {
dir(path: 'src/backend') {
sh 'ssh web@fufle.net touch /web/fufle.net/curenet/dev/backend/REMOVEME'
sh 'ssh web@fufle.net rm -rf /web/fufle.net/curenet/dev/backend/*'
sh 'scp -r ./ web@fufle.net:/web/fufle.net/curenet/dev/backend/'
}
}
}
}
}
}
}