Skip to content

Instantly share code, notes, and snippets.

@chamilaadhi
Last active May 6, 2021 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chamilaadhi/81241bf2e9c46b720ef61fb516e00249 to your computer and use it in GitHub Desktop.
Save chamilaadhi/81241bf2e9c46b720ef61fb516e00249 to your computer and use it in GitHub Desktop.
node {
properties([
pipelineTriggers([
[$class: 'GenericTrigger',
genericVariables: [
[ key: 'name', value: '$.data.name' ],
[ key: 'location', value: '$.data.path' ]
],
token: '123',
printContributedVariables: true,
printPostContent: true,
]
])
]
)
stage('Preparation') {
git branch: "dev",
url: 'https://github.com/chamilaadhi/poc-cicd-deployment-repo.git'
}
stage('Setup Environment for APICTL') {
sh '''#!/bin/bash
envs=$(apictl get envs --format "{{.Name}}")
if [ -z "$envs" ];
then
echo "No environment configured. Setting dev environment.."
apictl add env dev --apim https://${APIM_DEV_HOST}:9443 -k
else
echo "Environments :"$envs
if [[ $envs != *"dev"* ]]; then
echo "Dev environment is not configured. Setting dev environment.."
apictl add env dev --apim https://${APIM_DEV_HOST}:9443 -k
fi
fi
'''
}
stage('Deploy to Development Environment') {
sh '''#!/bin/bash
# download the artifact from the artifact repository
wget https://${ARTIFACTORY_HOST}/artifactory/${ARTIFACTORY_REPO}/$location
# derive param content name
fileName=$(echo $name | sed 's/\\(.*\\).zip/\\1 /')
deploymentName=$(echo $fileName | sed 's/\\(.*\\)_/\\1-/')
paramPath="DeploymentArtifacts_"$deploymentName
echo "Param path :"$paramPath
# login to the dev environment
apictl login dev -u admin -p admin -k
# import the artifact
message=$(apictl import api -f $name --params $paramPath -e dev --update -k)
if [ "$message" = "Successfully imported API." ]; then
echo "Successfully imported API."
else
echo $message
fi
rm $name
'''
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment