def remote = [:] remote.name = 'remote' remote.host = 'localhost' remote.user = 'simon' remote.identityFile = '/var/lib/jenkins/.ssh/id_rsa' remote.knownHosts = '/var/lib/jenkins/.ssh/known_hosts' remote.allowAnyHosts = true remote.retryCount = 3 remote.retryWaitSec = 3 logLevel = 'FINER' pipeline { agent none environment { GOOS='linux' CGO_ENABLED='0' HOME='.' } stages { stage('Parallel build & test') { failFast true parallel { stage('Build - web') { agent { docker { image 'node:10-alpine' } } steps { sh 'cd web/angular/ && npm install' sh 'cd web/angular/ && ./node_modules/\\@angular/cli/bin/ng build --prod --optimization --output-path "${WORKSPACE}/webroot"' stash includes: 'webroot/', name: 'webdist' } } stage('Build - api') { agent { docker { image 'golang:latest' } } steps { sh 'mkdir -p /go/src/github.com/task_tracker' sh 'cp -r api config main storage config.yml schema.sql "/go/src/github.com/task_tracker"' sh 'cd /go/src/github.com/task_tracker/main && go get ./...' sh 'cd /go/src/github.com/task_tracker/main && go build -a -installsuffix cgo -o "${WORKSPACE}/tt_api" .' stash includes: 'tt_api', name: 'apidist' } } stage('Test - api') { agent { docker { image 'golang:latest' args '--network "host"' } } steps { sh 'mkdir -p /go/src/github.com/task_tracker' sh 'cp -r api config main storage test config.yml schema.sql "/go/src/github.com/task_tracker"' sh 'cd /go/src/github.com/task_tracker/ && go get -t ./test/...' sh 'cd /go/src/github.com/task_tracker/test && go test .' } } } } stage('Deploy') { agent none steps { node('master') { unstash 'webdist' unstash 'apidist' sshCommand remote: remote, command: "cd task_tracker && rm -rf tt_api config.yml schema.sql webroot deploy.sh" sshPut remote: remote, from: 'tt_api', into: 'task_tracker/tt_api' sshPut remote: remote, from: 'config.yml', into: 'task_tracker/config.yml' sshPut remote: remote, from: 'schema.sql', into: 'task_tracker/schema.sql' sshPut remote: remote, from: 'webroot/', into: 'task_tracker' sshPut remote: remote, from: 'jenkins/deploy.sh', into: 'task_tracker/' sshCommand remote: remote, command: 'chmod +x task_tracker/deploy.sh && ./task_tracker/deploy.sh' } } } } }