pipeline { agent any environment { DatabaseUrl = sh(returnStdout: true, script: 'bash /var/lib/jenkins/variables/CureNet/var.sh dev DatabaseUrl').trim() ProjectPath = sh(returnStdout: true, script: 'bash /var/lib/jenkins/variables/CureNet/var.sh dev ProjectPath').trim() DatabaseUrlTesting = sh(returnStdout: true, script: 'bash /var/lib/jenkins/variables/CureNet/var.sh master 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 /usr/local/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 "echo `php8.0 -r 'echo md5(\"branch=${BRANCH_NAME};\");'` | php8.0 ../../tools/putenv/putenv.php .env.test APP_SECRET" sh "php8.0 ../../tools/putenv/putenv.php .env.test DATABASE_URL \"${DatabaseUrlTesting}\"" sh 'php8.0 /usr/local/bin/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 "echo `php8.0 -r 'echo md5(\"branch=${BRANCH_NAME};\");'` | php8.0 ../../tools/putenv/putenv.php .env APP_SECRET" sh "php8.0 ../../tools/putenv/putenv.php .env DATABASE_URL \"${DatabaseUrl}\"" sh 'php8.0 /usr/local/bin/composer dump-env prod' } } } } } 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 'master' branch 'staging' branch 'beta' branch 'dev' branch '29-profile-page' } } parallel { stage('Frontend') { steps { dir(path: 'src/frontend') { sh 'ssh web@fufle.net touch ${ProjectPath}/frontend/REMOVEME' sh 'ssh web@fufle.net rm -rf ${ProjectPath}/frontend/*' sh 'scp -r dist/* web@fufle.net:${ProjectPath}/frontend/' } } } stage('Backend') { steps { dir(path: 'src/backend') { sh 'ssh web@fufle.net touch ${ProjectPath}/backend/REMOVEME' sh 'ssh web@fufle.net rm -rf ${ProjectPath}/backend/*' sh 'scp -r ./* web@fufle.net:${ProjectPath}/backend/' sh 'scp -r ./.env web@fufle.net:${ProjectPath}/backend/.env' sh 'ssh web@fufle.net chmod 777 ${ProjectPath}/backend/var -R' sh 'ssh web@fufle.net "cd ${ProjectPath}/backend; php8.0 bin/console doctrine:schema:update --force"' sh 'ssh web@fufle.net "cd ${ProjectPath}/backend; php8.0 bin/console lexik:jwt:generate-keypair --skip-if-exists"' } } } } } } }