Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CloudBees Days Conjur Workshop 2019 - Pipeline Script for Simple Token App
pipeline {
agent any
stages {
stage ('Checkout SCM') {
steps {
checkout(
[
$class: 'GitSCM',
branches: [[name: '*/master']],
userRemoteConfigs: [[url: 'https://github.com/infamousjoeg/simple-token-app']]
]
)
}
}
stage ('Build Test Container') {
steps {
withCredentials([conjurSecretCredential(credentialsId: 'sta-token', variable: 'VALID_TOKEN')]) {
sh 'docker build -t sta:test .'
sh 'docker run --name sta_notoken -d sta:test'
sh 'docker run --name sta_invalidtoken -d -e PING_TOKEN=notValid sta:test'
sh 'docker run --name sta_validtoken -d -e PING_TOKEN=${VALID_TOKEN} sta:test'
}
}
}
stage ('Test Web App with no PING_TOKEN') {
steps {
script {
def PING_STATUS = sh (
script: 'docker exec -t sta_notoken curl http://localhost:5000',
returnStdout: true
).trim()
echo "The Status Code returned is: ${PING_STATUS}"
if (PING_STATUS != 'Unauthorized Request') {
sh 'exit 1'
}
}
}
}
stage ('Test Web App with invalid PING_TOKEN') {
steps {
script {
def PING_STATUS = sh (
script: 'docker exec -t sta_invalidtoken curl http://localhost:5000',
returnStdout: true
).trim()
echo "The Status Code returned is: ${PING_STATUS}"
if (PING_STATUS != 'Unauthorized Request') {
sh 'exit 1'
}
}
}
}
stage ('Test Web App with valid PING_TOKEN from CyberArk') {
steps {
script {
def PING_STATUS = sh (
script: 'docker exec -t sta_validtoken curl http://localhost:5000',
returnStdout: true
).trim()
echo "The Status Code returned is: ${PING_STATUS}"
if (PING_STATUS != 'Network Active' && PING_STATUS != 'Network Error') {
sh 'exit 1'
}
}
}
}
}
post {
always {
sh '''
docker rm -f sta_notoken sta_invalidtoken sta_validtoken
docker rmi sta:test
rm -rf *
'''
deleteDir()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.