Skip to content

Commit

Permalink
Set namespace names from env vars (#151)
Browse files Browse the repository at this point in the history
Set namespace names used in the pipeline via env vars.
This allows names to be changed in the applier config.
  • Loading branch information
bparry02 authored Sep 28, 2020
1 parent 564f114 commit 6f786dc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
3 changes: 3 additions & 0 deletions basic-spring-boot/.applier/group_vars/seed-hosts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ openshift_cluster_content:
params_from_vars:
APPLICATION_NAME: "{{ sb_application_name }}"
NAMESPACE: "{{ sb_build_namespace }}"
NAMESPACE_DEV: "{{ sb_dev_namespace }}"
NAMESPACE_STAGE: "{{ sb_stage_namespace }}"
NAMESPACE_PROD: "{{ sb_prod_namespace }}"
SOURCE_REPOSITORY_URL: "{{ sb_source_repository_url }}"
SOURCE_REPOSITORY_REF: "{{ sb_source_repository_ref }}"
APPLICATION_SOURCE_REPO: "{{ sb_application_repository_url }}"
Expand Down
21 changes: 20 additions & 1 deletion basic-spring-boot/.openshift/templates/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,20 @@ objects:
jenkinsPipelineStrategy:
jenkinsfilePath: ${PIPELINE_SCRIPT}
env:
- name: "APP_NAME"
value: "${APPLICATION_NAME}"
- name: "APPLICATION_SOURCE_REPO"
value: "${APPLICATION_SOURCE_REPO}"
- name: "APPLICATION_SOURCE_REF"
value: "${APPLICATION_SOURCE_REF}"
- name: "NAMESPACE_BUILD"
value: "${NAMESPACE}"
- name: "NAMESPACE_DEV"
value: "${NAMESPACE_DEV}"
- name: "NAMESPACE_STAGE"
value: "${NAMESPACE_STAGE}"
- name: "NAMESPACE_PROD"
value: "${NAMESPACE_PROD}"
- apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
Expand Down Expand Up @@ -84,7 +94,7 @@ parameters:
name: APPLICATION_NAME
required: true
value: basic-spring
- description: The namespace to deploy into
- description: The namespace that will contain the build resources defined in this template
name: NAMESPACE
required: true
- description: Git source URI for application
Expand All @@ -107,6 +117,15 @@ parameters:
- description: Path within Git project pointing to the pipeline run script
name: PIPELINE_SCRIPT
value: Jenkinsfile
- description: The namespace containing dev resources
name: NAMESPACE_DEV
required: true
- description: The namespace containing stage resources
name: NAMESPACE_STAGE
required: true
- description: The namespace containing prod resources
name: NAMESPACE_PROD
required: true
- description: GitHub trigger secret
from: '[a-zA-Z0-9]{8}'
generate: expression
Expand Down
11 changes: 5 additions & 6 deletions basic-spring-boot/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ retriever: modernSCM(
openshift.withCluster() {
env.NAMESPACE = openshift.project()
env.POM_FILE = env.BUILD_CONTEXT_DIR ? "${env.BUILD_CONTEXT_DIR}/pom.xml" : "pom.xml"
env.APP_NAME = "${JOB_NAME}".replaceAll(/-build.*/, '')
echo "Starting Pipeline for ${APP_NAME}..."
env.BUILD = "${env.NAMESPACE}"
env.DEV = "${APP_NAME}-dev"
env.STAGE = "${APP_NAME}-stage"
env.PROD = "${APP_NAME}-prod"
echo "Starting Pipeline for ${env.APP_NAME}..."
env.BUILD = "${env.NAMESPACE_BUILD}"
env.DEV = "${env.NAMESPACE_DEV}"
env.STAGE = "${env.NAMESPACE_STAGE}"
env.PROD = "${env.NAMESPACE_PROD}"
}

pipeline {
Expand Down

0 comments on commit 6f786dc

Please sign in to comment.