Added github-webhook payload as a parameter to the jenkins pipeline script.
The purpose is to take the version data from the github-webhook payload and use it as a tag when building docker images.
But I don’t know how to add version data from github-webhook payload.
I thought the best way was to use github’s tag function, but I couldn’t get it for the tag because that pipeline only works at pull request.
I thought I could get it through a branch name or a commit message, but I don’t know if this is okay.
What are some good ways to add version data to the github-webhook payload?
This is my jenkins pipeline script and it call upon pull request.
import groovy.json.JsonSlurper
def version = null
pipeline {
agent any
parameters { string(name: 'payload', defaultValue: '', description: 'github api payload') }
stages {
stage('Get Version') {
steps {
script {
def myobj = new JsonSlurper().parseText(payload)
version = myobj.???
}
}
}
stage('Build') {
steps {
sh '''
bash $HOME/my_pipeline/docker/image.sh
--build="APP_ENV=stag"
-- web ${version} 192.168.1.10:5000
'''
}
}
stage('Deploy') {
steps {
sh '''
bash $HOME/my_pipeline/docker/update.sh
--context=stag
--stack=ancean
-- web ${version} 192.168.1.10:5000
'''
}
}
}
}
I tried pull request by adding tag to commit.
Antoliny is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.