_template-service/Jenkinsfile
adam 9ace69a119
Some checks failed
gitea.arg.rip/_template-service/pipeline/head There was a failure building this commit
save the old appsettings.json
2024-12-13 21:13:00 -05:00

104 lines
3.7 KiB
Groovy

pipeline {
agent any
environment {
linuxServiceAccount=creds
linuxServiceAccountID=string
productiondatabase_connectionString=creds
targetHost=string
}
stages {
stage('build'){
steps{
//"hey self, what if once in your life you try a *different* language?" "then i'll update this file, moai.emoji."
dotnetBuild(outputDirectory: "./dist", project: "$REPO_NAME.csproj")
}
}
stage('test'){
steps{
//TODO: run tests
//TODO: publish tests in some nicely readable format
sh """#!/bin/bash
"""
}
}
stage ('upload') {
when {
//now my CI/CD is no longer continuous, it's just... automatic.
//(which is what I actually want tbh)
//but that does mean I have to put this condition in every single branch
branch "release"
}
steps{
withCredentials([sshUserPrivateKey(credentialsId: env.linuxServiceAccountID, keyFileVariable: 'PK')])
{
sh """#!/bin/bash
ssh -i \"$${PK}\" -tt $${linuxServiceAccount_USR}@$${targetHost} 'rm -rf temp_deploy & mkdir -p temp_deploy'
scp -i \"$${PK}\" -r dist $${linuxServiceAccount_USR}@$${env.targetHost}:temp_deploy
"""
}
}
}
stage ('stop')
{
when {
branch "release"
}
steps{
withCredentials([sshUserPrivateKey(credentialsId: env.linuxServiceAccountID, keyFileVariable: 'PK')])
{
sh """#!/bin/bash
ssh -i \"$${PK}\" -tt $${linuxServiceAccount_USR}@$${targetHost} 'systemctl --user stop $REPO_NAME'
"""
}
}
}
stage ('update db')
{
when {
branch "release"
}
steps{
//TODO: backup database
sh """#!/bin/bash
"""
sh """#!/bin/bash
dotnet ef database update --connection "$${env.productiondatabase_connectionString}"
"""
//TODO: if updating the db fails, restore the old one
sh """#!/bin/bash
"""
}
}
stage ('replace')
{
when {
branch "release"
}
steps{
withCredentials([sshUserPrivateKey(credentialsId: env.linuxServiceAccountID, keyFileVariable: 'PK')])
{
sh """#!/bin/bash
ssh -i \"$${PK}\" -tt $${linuxServiceAccount_USR}@$${targetHost} 'mv dist/appsettings.json appsettings.json'
ssh -i \"$${PK}\" -tt $${linuxServiceAccount_USR}@$${targetHost} 'rm -rf dist/ && mv temp_deploy/ dist/'
ssh -i \"$${PK}\" -tt $${linuxServiceAccount_USR}@$${targetHost} 'mv appsettings.json dist/appsettings.json'
"""
}
}
}
stage ('spin up')
{
when {
branch "release"
}
steps{
withCredentials([sshUserPrivateKey(credentialsId: env.linuxServiceAccountID, keyFileVariable: 'PK')])
{
sh """#!/bin/bash
ssh -i \"$${PK}\" -tt $${linuxServiceAccount_USR}@$${targetHost} 'systemctl --user start $REPO_NAME'
"""
}
}
}
}
}