CureNet/Jenkinsfile

197 lines
4.9 KiB
Plaintext
Raw Normal View History

2021-07-27 11:43:23 +00:00
pipeline {
agent any
2021-07-27 12:05:54 +00:00
environment {
DatabaseUrl = sh(returnStdout: true, script: 'bash /var/lib/jenkins/variables/CureNet/var.sh ${BRANCH_NAME} DatabaseUrl').trim()
2021-07-27 12:38:48 +00:00
DatabaseUrlTesting = sh(returnStdout: true, script: 'bash /var/lib/jenkins/variables/CureNet/var.sh test DatabaseUrl').trim()
2021-07-27 12:05:54 +00:00
}
2021-07-27 11:43:23 +00:00
stages {
stage('Pull') {
steps {
git(url: 'http://git.fufle.net/Community/CureNet.git', branch: '${BRANCH_NAME}', credentialsId: '799188a2-c281-4e4c-b78f-c82132ea792b', poll: true)
}
}
2021-07-27 12:05:54 +00:00
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')
}
}
}
}
2021-07-27 11:43:23 +00:00
stage('Install') {
parallel {
stage('Frontend') {
steps {
2021-07-27 12:19:14 +00:00
dir(path: 'src/frontend') {
2021-07-27 12:05:54 +00:00
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'
2021-07-27 11:43:23 +00:00
sh 'npm ci'
}
}
}
stage('Backend') {
steps {
2021-07-27 12:19:14 +00:00
dir(path: 'src/backend') {
2021-07-27 12:05:54 +00:00
sh 'php8.0 /bin/composer install'
2021-07-27 11:43:23 +00:00
}
}
}
}
}
2021-07-27 12:38:48 +00:00
stage('Configure for tests') {
2021-07-27 11:43:23 +00:00
parallel {
stage('Frontend') {
steps {
2021-07-27 12:19:14 +00:00
dir(path: 'src/frontend') {
2021-07-27 11:43:23 +00:00
sh 'echo skip'
}
}
}
stage('Backend') {
steps {
2021-07-27 12:19:14 +00:00
dir(path: 'src/backend') {
2021-07-27 12:05:54 +00:00
sh 'APP_SECRET=`php8.0 -r "echo md5(\\"branch=${BRANCH_NAME};\\");"` && sed -i "s/APP_SECRET=.*/APP_SECRET=${APP_SECRET}/g" .env'
2021-07-27 12:38:48 +00:00
sh 'sed -i "s/DATABASE_URL=.*/DATABASE_URL=${DatabaseUrlTesting}/g" .env.test'
sh 'composer dump-env test'
sh 'php bin/console doctrine:schema:update --force';
2021-07-27 11:43:23 +00:00
}
}
}
}
}
stage('Test') {
parallel {
stage('Frontend') {
steps {
2021-07-27 12:19:14 +00:00
dir(path: 'src/frontend') {
2021-07-27 12:05:54 +00:00
sh 'ng lint'
}
}
}
stage('Backend') {
steps {
2021-07-27 12:19:14 +00:00
dir(path: 'src/backend') {
2021-07-27 12:05:54 +00:00
sh 'php8.0 vendor/bin/phpunit'
}
}
}
}
}
2021-07-27 12:38:48 +00:00
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'
}
}
}
}
}
2021-07-27 12:05:54 +00:00
stage('Build') {
parallel {
stage('Frontend') {
steps {
2021-07-27 12:19:14 +00:00
dir(path: 'src/frontend') {
2021-07-27 12:05:54 +00:00
sh 'ng b -c production'
2021-07-27 11:43:23 +00:00
}
}
}
stage('Backend') {
steps {
2021-07-27 12:19:14 +00:00
dir(path: 'src/backend') {
2021-07-27 12:05:54 +00:00
sh 'echo skip'
2021-07-27 11:43:23 +00:00
}
}
}
}
}
stage('Deploy') {
2021-07-27 12:05:54 +00:00
when {
anyOf {
branch 'prod'
branch 'staging'
branch 'beta'
branch 'dev'
}
}
2021-07-27 11:43:23 +00:00
parallel {
stage('Frontend') {
steps {
2021-07-27 12:19:14 +00:00
dir(path: 'src/frontend') {
2021-07-27 11:43:23 +00:00
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 {
2021-07-27 12:19:14 +00:00
dir(path: 'src/backend') {
2021-07-27 11:43:23 +00:00
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/'
}
}
}
}
}
}
}