diff --git a/Jenkinsfile b/Jenkinsfile index 8c26407..5bed68f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,14 +1,14 @@ pipeline { agent any environment { - linuxServiceAccount=credentials('UUID') - productiondatabase_connectionString="?" - targetServer="string" + linuxServiceAccount=creds + productiondatabase_connectionString=creds + targetHost=string } stages { stage('build'){ //"hey self, what if once in your life you try a *different* language?" "then i'll update this file, moai.emoji." - //dotnetBuild(outputDirectory: "./", project: "Deployment/Deployment.csproj") + dotnetBuild(outputDirectory: "./dist", project: "$REPO_NAME.csproj") } stage('test'){ //TODO: run tests @@ -22,9 +22,14 @@ pipeline { branch "release" } steps{ - sh 'ssh ${env.targetServer} rm -rf temp_deploy' - sh 'ssh ${env.targetServer} mkdir -p temp_deploy' - sh 'scp -r dist ${env.targetServer}:temp_deploy' + sshagent([linuxServiceAccount]) + { + ssh ${env.targetHost} 'bash -s' << 'ENDSSH' + rm -rf temp_deploy + mkdir -p temp_deploy + ENDSSH + sh 'scp -r dist ${env.targetHost}:temp_deploy' + } } } stage ('stop') @@ -34,13 +39,15 @@ pipeline { } steps{ script{ - //user is the service user - ssh ${env.targetServer} 'bash -s' << 'ENDSSH' - systemctl --user stop $svcname - ENDSSH + sshagent([linuxServiceAccount]) { + ssh ${env.targetHost} 'bash -s' << 'ENDSSH' + systemctl --user stop $REPO_NAME + ENDSSH + } } } } + ---dbstart--- stage ('backup db') { when { @@ -58,13 +65,16 @@ pipeline { //TODO: update database //TODO: if updating the db fails, restore the old one } + ---dbend--- stage ('replace') { when { branch "release" } steps{ - sh 'ssh ${env.targetServer} "rm -rf dist/ && mv temp_deploy/ dist/"' + sshagent([linuxServiceAccount]) { + ssh ${env.targetHost} "rm -rf dist/ && mv temp_deploy/ dist/" + } } } stage ('spin up') @@ -74,9 +84,11 @@ pipeline { } steps{ script{ - ssh ${env.targetServer} 'bash -s' << 'ENDSSH' - systemctl --user start $svcname - ENDSSH + sshagent([linuxServiceAccount]) { + ssh ${env.targetHost} 'bash -s' << 'ENDSSH' + systemctl --user start $REPO_NAME + ENDSSH + } } } }