Browse Source

improve jenkins support

pull/50/head
Nicolas Massé 7 years ago
parent
commit
589b4c221a
  1. 73
      support/jenkins/Jenkinsfile
  2. 5
      support/jenkins/README.md

73
support/jenkins/Jenkinsfile

@ -4,27 +4,75 @@
* This Jenkins Pipeline depends on the following plugins : * This Jenkins Pipeline depends on the following plugins :
* - Credentials Binding (https://plugins.jenkins.io/credentials-binding) * - Credentials Binding (https://plugins.jenkins.io/credentials-binding)
* - Ansible (https://plugins.jenkins.io/ansible) * - Ansible (https://plugins.jenkins.io/ansible)
* - Ansi Color (https://plugins.jenkins.io/ansicolor)
*/ */
pipeline { pipeline {
agent { label 'jenkins-ansible-slave.latest' } agent { label 'jenkins-ansible-slave.latest' }
parameters { parameters {
// Environment parameters
credentials(name: 'THREESCALE_CICD_ACCESS_TOKEN', description: 'The 3scale Access Token', credentialType: "Secret text", required: true) credentials(name: 'THREESCALE_CICD_ACCESS_TOKEN', description: 'The 3scale Access Token', credentialType: "Secret text", required: true)
credentials(name: 'THREESCALE_CICD_SSO_ISSUER_ENDPOINT', description: 'The SSO Issuer Endpoint when deploying an API with OpenID Connect', credentialType: "Secret text", required: false) credentials(name: 'THREESCALE_CICD_SSO_ISSUER_ENDPOINT', description: 'The SSO Issuer Endpoint when deploying an API with OpenID Connect', credentialType: "Secret text", required: false)
string(name: 'THREESCALE_PORTAL_HOSTNAME', description: 'The 3scale Admin Portal hostname') string(name: 'THREESCALE_PORTAL_HOSTNAME', description: 'The 3scale Admin Portal hostname')
string(name: 'THREESCALE_CICD_PRIVATE_BASE_URL', description: 'The 3scale private base URL', defaultValue: 'https://echo-api.3scale.net')
string(name: 'THREESCALE_CICD_API_SYSTEM_NAME', description: 'Override the 3scale Service system_name')
string(name: 'THREESCALE_CICD_API_BASE_SYSTEM_NAME', description: 'Define the base name to compute the final system_name')
string(name: 'THREESCALE_CICD_WILDCARD_DOMAIN', description: 'Automatically defines the APIcast public URLs based on a scheme')
string(name: 'THREESCALE_CICD_API_ENVIRONMENT_NAME', description: 'Prefixes all services with an environment name to prevent any name collision when deploying the same API multiple times on the same 3scale instance')
string(name: 'THREESCALE_CICD_APICAST_SANDBOX_ENDPOINT', description: 'Defines the Public Staging Base URL')
string(name: 'THREESCALE_CICD_APICAST_PRODUCTION_ENDPOINT', description: 'Defines the Public Production Base URL')
// Details about the API to deploy
string(name: 'GIT_REPOSITORY', description: 'The GIT repository to checkout, containing the OpenAPI Specifications') string(name: 'GIT_REPOSITORY', description: 'The GIT repository to checkout, containing the OpenAPI Specifications')
string(name: 'GIT_BRANCH', description: 'The GIT branch or tag to checkout, containing the OpenAPI Specifications', defaultValue: 'master') string(name: 'GIT_BRANCH', description: 'The GIT branch or tag to checkout, containing the OpenAPI Specifications', defaultValue: 'master')
string(name: 'OPENAPI_FILE', description: 'The path to the OpenAPI Specification within the GIT Repository') string(name: 'OPENAPI_FILE', description: 'The path to the OpenAPI Specification within the GIT Repository')
string(name: 'THREESCALE_CICD_PRIVATE_BASE_URL', description: 'The 3scale private base URL', defaultValue: 'https://echo-api.3scale.net') booleanParam(name: 'THREESCALE_CICD_APICAST_POLICIES_CORS', description: 'Allows to enable the CORS policy onto APICast gateway', defaultValue: false)
string(name: 'THREESCALE_CICD_OPENAPI_SMOKETEST_OPERATION', description: 'Defines the OpenAPI Specification method to use for smoke tests')
string(name: 'THREESCALE_CICD_API_BASEPATH', description: 'Overrides the OpenAPI basePath field')
choice(name: 'THREESCALE_CICD_OPENAPI_FILE_FORMAT', description: 'Read the OpenAPI file as YAML or JSON', choices: [ "YAML", "JSON" ])
// Misc. params
booleanParam(name: 'THREESCALE_CICD_VALIDATE_OPENAPI', description: 'Validates the OpenAPI Specification file against the official schema', defaultValue: true)
booleanParam(name: 'ANSIBLE_VERBOSE', description: 'Run Ansible in verbose mode (-v)', defaultValue: false)
} }
stages { stages {
stage("Pre-requisites") {
steps {
script {
if (paramIsEmpty(params.THREESCALE_CICD_ACCESS_TOKEN)) {
currentBuild.result = 'ABORTED'
error("The 3scale Access Token cannot be left empty")
}
if (paramIsEmpty(params.THREESCALE_PORTAL_HOSTNAME)) {
currentBuild.result = 'ABORTED'
error("The 3scale Admin Portal hostname cannot be left empty")
}
if (params.THREESCALE_PORTAL_HOSTNAME.startsWith("http://") || params.THREESCALE_PORTAL_HOSTNAME.startsWith("https://")) {
currentBuild.result = 'ABORTED'
error("The 3scale Admin Portal hostname must be the bare hostname (no http:// or https://)")
}
if (paramIsEmpty(params.GIT_REPOSITORY)) {
currentBuild.result = 'ABORTED'
error("The GIT Repository URL cannot be left empty")
}
if (paramIsEmpty(params.GIT_BRANCH)) {
currentBuild.result = 'ABORTED'
error("The GIT Repository Branch / Tag name cannot be left empty")
}
if (paramIsEmpty(params.OPENAPI_FILE)) {
currentBuild.result = 'ABORTED'
error("The path to the OpenAPI Specification within the GIT Repository cannot be left empty")
}
}
}
}
stage("GIT Checkout") { stage("GIT Checkout") {
steps { steps {
// Checkout the GIT repository containing the Ansible Playbook // Checkout the GIT repository containing the Ansible Playbook
checkout scm checkout scm
//git url: 'https://github.com/nmasse-itix/threescale-cicd.git'
// Checkout the GIT repository containing the OpenAPI Specification to provision // Checkout the GIT repository containing the OpenAPI Specification to provision
checkout([ $class: 'GitSCM', checkout([ $class: 'GitSCM',
@ -38,17 +86,28 @@ pipeline {
stage("Deploy an API to 3scale") { stage("Deploy an API to 3scale") {
steps { steps {
ansiColor('xterm') { script {
withCredentials([ string(credentialsId: params.THREESCALE_CICD_ACCESS_TOKEN, variable: 'THREESCALE_CICD_ACCESS_TOKEN'), // Generate the credential bindings:
string(credentialsId: params.THREESCALE_CICD_SSO_ISSUER_ENDPOINT, variable: 'THREESCALE_CICD_SSO_ISSUER_ENDPOINT')]) { // - THREESCALE_CICD_ACCESS_TOKEN is mandatory
// - THREESCALE_CICD_SSO_ISSUER_ENDPOINT is optional
credentialBindings = [ string(credentialsId: params.THREESCALE_CICD_ACCESS_TOKEN, variable: 'THREESCALE_CICD_ACCESS_TOKEN') ];
if (! paramIsEmpty(params.THREESCALE_CICD_SSO_ISSUER_ENDPOINT)) {
credentialBindings.add(string(credentialsId: params.THREESCALE_CICD_SSO_ISSUER_ENDPOINT, variable: 'THREESCALE_CICD_SSO_ISSUER_ENDPOINT'))
}
}
// Run the Ansible Playbook
withCredentials(credentialBindings) {
ansiblePlaybook(playbook: 'support/jenkins/deploy-api.yaml', ansiblePlaybook(playbook: 'support/jenkins/deploy-api.yaml',
extraVars: [ threescale_cicd_openapi_file: 'api/' + params.OPENAPI_FILE ], extraVars: [ threescale_cicd_openapi_file: 'api/' + params.OPENAPI_FILE ],
/* extras: '-v', // verbose mode */ extras: paramIsEmpty(params.ANSIBLE_VERBOSE) ? '' : '-v')
colorized: true)
} }
} }
} }
} }
} }
def credentialBindings = null;
def paramIsEmpty(param) {
return param == null || param == "";
} }

5
support/jenkins/README.md

@ -1,5 +1,8 @@
# Using this Ansible role from Jenkins # Using this Ansible role from Jenkins
You can use this Ansible role from Jenkins to include 3scale in your Continuous
Deployment pipeline.
To use this role from Jenkins, you will need to: To use this role from Jenkins, you will need to:
- Create the Jenkins Slave image for Ansible - Create the Jenkins Slave image for Ansible
@ -37,8 +40,6 @@ oc logs -f bc/jenkins-ansible-slave
- Go to the **Available** tab - Go to the **Available** tab
- In the **Filter** text field, type `Ansible` - In the **Filter** text field, type `Ansible`
- In the list, find the **Ansible plugin** and check its box in the **Enabled** column - In the list, find the **Ansible plugin** and check its box in the **Enabled** column
- In the **Filter** text field, type `Ansi Color`
- In the list, find the **Ansi Color** and check its box in the **Enabled** column
- Click **Install without restart** - Click **Install without restart**
## Create the pipeline that calls Ansible ## Create the pipeline that calls Ansible

Loading…
Cancel
Save