OpenShift CI/CD Operations: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 12: Line 12:
{{Internal|OpenShift Set Up a Standalone, cicd-template.yaml-Based Jenkins|Set Up a Standalone, cicd-template.yaml-Based Jenkins}}
{{Internal|OpenShift Set Up a Standalone, cicd-template.yaml-Based Jenkins|Set Up a Standalone, cicd-template.yaml-Based Jenkins}}


=Set Up a Jenkins CI/CD Pipeline=
=Create the Jenkins Components=
 
==Grant Jenkins Needed Privileges for the Projects that Require CI/CD Services==
 
For reasons behind these actions, see: {{Internal|Jenkins and OpenShift#Security_Considerations|Jenkins and OpenShift - Security Considerations}}
 
[[Oc_policy#add-role-to-user|oc policy add-role-to-user]] edit system:serviceaccount:cicd:jenkins -n dev
[[Oc_policy#add-role-to-user|oc policy add-role-to-user]] edit system:serviceaccount:cicd:jenkins -n stage
 
==Create the CI/CD Components==


  oc project cicd
  oc project cicd

Revision as of 02:39, 22 November 2017

Internal

Overview

Set Up a CI/CD Pipeline

Set Up a Project-Collocated jenkins-persistent-Based Jenkins
Set Up a Standalone, cicd-template.yaml-Based Jenkins

Create the Jenkins Components

oc project cicd

oc process -f ./cicd-template.yaml --param DEV_PROJECT=dev --param STAGE_PROJECT=stage \
| oc create -f - 

A template example for OpenShift 3.5 is available at https://github.com/OpenShiftDemos/openshift-cd-demo/blob/ocp-3.5/cicd-template.yaml. A version is also available here: OpenShift CICD Template Example.

Note that "jenkins-persistent" and "jenkins-ephemeral" are available templates in the "openshift" project, they probably can be also used:

oc get templates -n openshift | grep jenkins

Configure Jenkins

oc project cicd
oc set resources dc/jenkins --limits=memory=1Gi

Checkpoint

Configure the Jenkins Pipeline

New Item -> "hello-nodejs-pipeline" -> Pipeline -> OK

Pipeline -> Definition -> Pipeline script:

node {
  stage ("Build") {
    echo '*** Build Starting ***'
    openshiftBuild apiURL: 'https://openshift.default.svc.cluster.local', authToken: '', bldCfg: 'hello-nodejs', buildName: '', checkForTriggeredDeployments: 'false', commitID: '', namespace: '', showBuildLogs: 'false', verbose: 'false', waitTime: ''
    openshiftVerifyBuild apiURL: 'https://openshift.default.svc.cluster.local', authToken: '', bldCfg: 'hello-nodejs', checkForTriggeredDeployments: 'false', namespace: '', verbose: 'false'
    echo '*** Build Complete ***'
  }
  stage ("Deploy") {
    echo '*** Deployment Starting ***'
    openshiftDeploy apiURL: 'https://openshift.default.svc.cluster.local', authToken: '', depCfg: 'hello-nodejs', namespace: '', verbose: 'false', waitTime: ''
    openshiftVerifyDeployment apiURL: 'https://openshift.default.svc.cluster.local', authToken: '', depCfg: 'hello-nodejs', namespace: '', replicaCount: '1', verbose: 'false', verifyReplicaCount: 'false', waitTime: ''
    echo '*** Deployment Complete ***'
  }
  stage ("Verify") {
    echo '*** Service Verification Starting ***'
    openshiftVerifyService apiURL: 'https://openshift.default.svc.cluster.local', authToken: '', namespace: '', svcName: 'hello-nodejs', verbose: 'false'
    echo '*** Service Verification Complete ***'
  }
}