add jenkinsfile

This commit is contained in:
adamoutler 2023-02-12 20:22:52 +00:00
parent 87153f4194
commit b513b38398

69
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,69 @@
#! /bin/groovy
pipeline {
agent {
docker {
alwaysPull true
image 'alpine:3.14'
label 'Wrangler1'
args '-u root'
}
}
stages {
stage('Prepare Environment'){
steps{
sh "#!/bin/sh \n" +
'id; apk add docker openrc git'
}
}
stage('Obtain Source'){
steps {
git branch: 'main', url: 'https://git.adamoutler.com/aoutler/aidgaf-server.git'
}
}
stage('Build in docker') {
steps {
// Get some code from a Git repository
sh "#!/bin/sh \n" +
'docker build -t aidgaf .'
}
}
stage ("setup credentials"){
steps{
withCredentials([ sshUserPrivateKey(credentialsId: 'dockeruserOn192.168.1.115', keyFileVariable: 'sshkey', usernameVariable: 'user')]) {
sh "#!/bin/sh \n" +
'set +e; docker stop aidgaf-server||echo machine stopped; docker rm aidgaf-server||echo machine does not exist; set -e'
}
}
}
stage ('export docker container'){
steps {
sh "#!/bin/sh \n" +
'set +e; docker stop aidgaf-server||echo machine stopped; docker rm aidgaf-server||echo machine does not exist; set -e'
withCredentials([
string(credentialsId: 'OpenAI-API-Token', variable: 'OPEN_AI_TOKEN'),
string(credentialsId: 'PapaHashingSecret', variable: 'PAPA_HASH'),
sshUserPrivateKey(credentialsId: 'dockeruserOn192.168.1.115', keyFileVariable: 'sshkey', usernameVariable: 'user')
]) {
sh "#!/bin/sh \n" +
'mkdir -p ~/.ssh; cp "${sshkey}" ~/.ssh/id_rsa'
sh "#!/bin/sh \n" +
'docker run --name=aidgaf-server -eSERVERPORT=8087 -eHOSTNAME=0.0.0.0 -eHASHKEY="${PAPA_HASH}" -eAPIKEY="${OPEN_AI_TOKEN}" -p8087:8087 -d --restart=always aidgaf'
}
}
}
// To run Maven on a Windows agent, use
// bat "mvn -Dmaven.test.failure.ignore=true clean package"
}
}