2024-11-16 22:19:51 -05:00
|
|
|
pipeline {
|
|
|
|
agent any
|
2024-11-17 23:25:20 -05:00
|
|
|
environment {
|
2024-11-19 02:08:20 -05:00
|
|
|
linuxServiceAccount=creds
|
2024-12-13 16:51:18 -05:00
|
|
|
linuxServiceAccountID=string
|
2024-11-19 02:08:20 -05:00
|
|
|
productiondatabase_connectionString=creds
|
|
|
|
targetHost=string
|
2024-11-17 23:25:20 -05:00
|
|
|
}
|
2024-11-16 22:19:51 -05:00
|
|
|
stages {
|
2024-11-17 13:23:08 -05:00
|
|
|
stage('build'){
|
2024-12-07 01:55:09 -05:00
|
|
|
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")
|
|
|
|
}
|
2024-11-17 13:23:08 -05:00
|
|
|
}
|
|
|
|
stage('test'){
|
2024-12-07 01:55:09 -05:00
|
|
|
steps{
|
|
|
|
//TODO: run tests
|
|
|
|
//TODO: publish tests in some nicely readable format
|
|
|
|
sh """#!/bin/bash
|
|
|
|
"""
|
|
|
|
}
|
2024-11-17 13:23:08 -05:00
|
|
|
}
|
|
|
|
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{
|
2024-12-13 16:51:18 -05:00
|
|
|
withCredentials([sshUserPrivateKey(credentialsId: env.linuxServiceAccountID, keyFileVariable: 'PK')])
|
2024-11-19 02:08:20 -05:00
|
|
|
{
|
2024-12-07 01:55:09 -05:00
|
|
|
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
|
|
|
|
"""
|
2024-11-19 02:08:20 -05:00
|
|
|
}
|
2024-11-17 13:23:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
stage ('stop')
|
|
|
|
{
|
|
|
|
when {
|
|
|
|
branch "release"
|
|
|
|
}
|
2024-11-17 23:25:20 -05:00
|
|
|
steps{
|
2024-12-13 16:51:18 -05:00
|
|
|
withCredentials([sshUserPrivateKey(credentialsId: env.linuxServiceAccountID, keyFileVariable: 'PK')])
|
2024-12-07 01:55:09 -05:00
|
|
|
{
|
|
|
|
sh """#!/bin/bash
|
|
|
|
ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'systemctl --user stop $REPO_NAME'
|
|
|
|
"""
|
2024-11-17 23:25:20 -05:00
|
|
|
}
|
2024-11-17 13:23:08 -05:00
|
|
|
}
|
|
|
|
}
|
2024-12-13 16:51:18 -05:00
|
|
|
stage ('update db')
|
2024-11-17 13:23:08 -05:00
|
|
|
{
|
|
|
|
when {
|
|
|
|
branch "release"
|
|
|
|
}
|
2024-11-17 23:25:20 -05:00
|
|
|
steps{
|
|
|
|
//TODO: backup database
|
2024-12-07 01:55:09 -05:00
|
|
|
sh """#!/bin/bash
|
|
|
|
"""
|
2024-12-13 16:51:18 -05:00
|
|
|
|
|
|
|
sh """#!/bin/bash
|
|
|
|
pushd dist
|
|
|
|
dotnet ef database update --connection "${env.productiondatabase_connectionString}"
|
|
|
|
popd
|
|
|
|
"""
|
2024-12-07 01:55:09 -05:00
|
|
|
//TODO: if updating the db fails, restore the old one
|
|
|
|
sh """#!/bin/bash
|
|
|
|
"""
|
|
|
|
}
|
2024-11-17 13:23:08 -05:00
|
|
|
}
|
|
|
|
stage ('replace')
|
|
|
|
{
|
|
|
|
when {
|
|
|
|
branch "release"
|
|
|
|
}
|
2024-11-17 23:25:20 -05:00
|
|
|
steps{
|
2024-12-13 16:51:18 -05:00
|
|
|
withCredentials([sshUserPrivateKey(credentialsId: env.linuxServiceAccountID, keyFileVariable: 'PK')])
|
2024-12-07 01:55:09 -05:00
|
|
|
{
|
|
|
|
sh """#!/bin/bash
|
|
|
|
ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'rm -rf dist/ && mv temp_deploy/ dist/'
|
|
|
|
"""
|
2024-11-19 02:08:20 -05:00
|
|
|
}
|
2024-11-17 23:25:20 -05:00
|
|
|
}
|
2024-11-17 13:23:08 -05:00
|
|
|
}
|
|
|
|
stage ('spin up')
|
|
|
|
{
|
|
|
|
when {
|
|
|
|
branch "release"
|
|
|
|
}
|
2024-11-17 23:25:20 -05:00
|
|
|
steps{
|
2024-12-13 16:51:18 -05:00
|
|
|
withCredentials([sshUserPrivateKey(credentialsId: env.linuxServiceAccountID, keyFileVariable: 'PK')])
|
2024-12-07 01:55:09 -05:00
|
|
|
{
|
|
|
|
sh """#!/bin/bash
|
|
|
|
ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'systemctl --user start $REPO_NAME'
|
|
|
|
"""
|
2024-11-17 23:25:20 -05:00
|
|
|
}
|
2024-11-17 13:23:08 -05:00
|
|
|
}
|
2024-11-16 22:19:51 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|