diff --git a/Jenkinsfile b/Jenkinsfile index e398b21..85ceb57 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,10 @@ pipeline { agent any + + environment { + DatabaseUrl = sh(returnStdout: true, script: 'bash /var/lib/jenkins/variables/CureNet/var.sh ${BRANCH_NAME} DatabaseUrl').trim() + } + stages { stage('Pull') { steps { @@ -7,11 +12,34 @@ pipeline { } } + 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: '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' } @@ -21,7 +49,7 @@ pipeline { stage('Backend') { steps { dir(path: 'backend') { - sh 'composer install' + sh 'php8.0 /bin/composer install' } } @@ -44,6 +72,8 @@ pipeline { stage('Backend') { steps { dir(path: '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' } @@ -58,7 +88,7 @@ pipeline { stage('Frontend') { steps { dir(path: 'frontend') { - sh 'echo skip' + sh 'ng lint' } } @@ -67,7 +97,30 @@ pipeline { stage('Backend') { steps { dir(path: 'backend') { - sh 'php vendor/bin/phpunit' + sh 'php8.0 vendor/bin/phpunit' + } + + } + } + + } + } + + stage('Build') { + parallel { + stage('Frontend') { + steps { + dir(path: 'frontend') { + sh 'ng b -c production' + } + + } + } + + stage('Backend') { + steps { + dir(path: 'backend') { + sh 'echo skip' } } @@ -77,6 +130,16 @@ pipeline { } stage('Deploy') { + when { + anyOf { + branch 'prod' + branch 'staging' + branch 'beta' + branch 'dev' + } + + } + parallel { stage('Frontend') { steps { diff --git a/src/frontend/src/environments/environment.prod.ts b/src/frontend/src/environments/environment.prod.ts index 3612073..c831413 100644 --- a/src/frontend/src/environments/environment.prod.ts +++ b/src/frontend/src/environments/environment.prod.ts @@ -1,3 +1,5 @@ export const environment = { - production: true + production: true, + buildId: -1001, + buildTime: -1002, }; diff --git a/src/frontend/src/environments/environment.ts b/src/frontend/src/environments/environment.ts index 30d7bcc..50099fc 100644 --- a/src/frontend/src/environments/environment.ts +++ b/src/frontend/src/environments/environment.ts @@ -3,7 +3,9 @@ // The list of file replacements can be found in `angular.json`. export const environment = { - production: false + production: false, + buildId: -1001, + buildTime: -1002, }; /*