diff --git a/Jenkinsfile b/Jenkinsfile index 5bed68f..eee3cca 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,12 +7,18 @@ pipeline { } 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: "./dist", project: "$REPO_NAME.csproj") + 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'){ - //TODO: run tests - //TODO: publish tests in some nicely readable format + steps{ + //TODO: run tests + //TODO: publish tests in some nicely readable format + sh """#!/bin/bash + """ + } } stage ('upload') { when { @@ -22,13 +28,12 @@ pipeline { branch "release" } steps{ - sshagent([linuxServiceAccount]) + withCredentials([sshUserPrivateKey(credentialsId: env.linuxServiceAccount, keyFileVariable: 'PK')]) { - ssh ${env.targetHost} 'bash -s' << 'ENDSSH' - rm -rf temp_deploy - mkdir -p temp_deploy - ENDSSH - sh 'scp -r dist ${env.targetHost}:temp_deploy' + 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 + """ } } } @@ -38,16 +43,14 @@ pipeline { branch "release" } steps{ - script{ - sshagent([linuxServiceAccount]) { - ssh ${env.targetHost} 'bash -s' << 'ENDSSH' - systemctl --user stop $REPO_NAME - ENDSSH - } + withCredentials([sshUserPrivateKey(credentialsId: env.linuxServiceAccount, keyFileVariable: 'PK')]) + { + sh """#!/bin/bash + ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'systemctl --user stop $REPO_NAME' + """ } } } - ---dbstart--- stage ('backup db') { when { @@ -55,6 +58,8 @@ pipeline { } steps{ //TODO: backup database + sh """#!/bin/bash + """ } } stage ('update db') @@ -62,18 +67,24 @@ pipeline { when { branch "release" } - //TODO: update database - //TODO: if updating the db fails, restore the old one + steps{ + //TODO: update database + //TODO: if updating the db fails, restore the old one + sh """#!/bin/bash + """ + } } - ---dbend--- stage ('replace') { when { branch "release" } steps{ - sshagent([linuxServiceAccount]) { - ssh ${env.targetHost} "rm -rf dist/ && mv temp_deploy/ dist/" + withCredentials([sshUserPrivateKey(credentialsId: env.linuxServiceAccount, keyFileVariable: 'PK')]) + { + sh """#!/bin/bash + ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'rm -rf dist/ && mv temp_deploy/ dist/' + """ } } } @@ -83,12 +94,11 @@ pipeline { branch "release" } steps{ - script{ - sshagent([linuxServiceAccount]) { - ssh ${env.targetHost} 'bash -s' << 'ENDSSH' - systemctl --user start $REPO_NAME - ENDSSH - } + withCredentials([sshUserPrivateKey(credentialsId: env.linuxServiceAccount, keyFileVariable: 'PK')]) + { + sh """#!/bin/bash + ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'systemctl --user start $REPO_NAME' + """ } } }