├── Jenkinsfile ├── Jenkinsfile1.txt ├── Jenkinsfile2.txt ├── pipeline.yml ├── pipelines example.tiff └── readme.md /Jenkinsfile: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent any 3 | stages { 4 | stage('Build In Development') { 5 | steps { 6 | script { 7 | openshift.withCluster() { 8 | openshift.withProject("development") { 9 | openshift.selector("bc", "myapp").startBuild().logs('-f') 10 | } 11 | } 12 | } 13 | } 14 | } 15 | stage('Deploy In Development') { 16 | steps { 17 | script { 18 | openshift.withCluster() { 19 | openshift.withProject("development") { 20 | openshift.selector("dc", "myapp").rollout().latest() 21 | } 22 | } 23 | } 24 | script { 25 | openshift.withCluster() { 26 | openshift.withProject("development") { 27 | openshift.selector("dc", "myapp").scale("--replicas=3") 28 | } 29 | } 30 | } 31 | } 32 | } 33 | stage('Promote to QA') { 34 | steps { 35 | script { 36 | openshift.withCluster() { 37 | openshift.withProject("development") { 38 | openshift.tag("development/myapp:latest", "development/myapp:promoteToQA") 39 | } 40 | } 41 | } 42 | } 43 | } 44 | stage('Deploy In QA') { 45 | steps { 46 | script { 47 | openshift.withCluster() { 48 | openshift.withProject("testing") { 49 | openshift.selector("dc", "myapp").rollout().latest() 50 | } 51 | } 52 | } 53 | script { 54 | openshift.withCluster() { 55 | openshift.withProject("testing") { 56 | openshift.selector("dc", "myapp").scale("--replicas=2") 57 | } 58 | } 59 | } 60 | } 61 | } 62 | 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Jenkinsfile1.txt: -------------------------------------------------------------------------------- 1 | node('maven') { 2 | stage 'build' 3 | openshiftBuild(buildConfig: 'myphp', showBuildLogs: 'true') 4 | stage 'deploy' 5 | openshiftDeploy(deploymentConfig: 'myphp') 6 | openshiftScale(deploymentConfig: 'myphp',replicaCount: '2') 7 | } 8 | -------------------------------------------------------------------------------- /Jenkinsfile2.txt: -------------------------------------------------------------------------------- 1 | node('') { 2 | stage 'buildInDevelopment' 3 | openshiftBuild(namespace: 'development', buildConfig: 'myapp', showBuildLogs: 'true') 4 | stage 'deployInDevelopment' 5 | openshiftDeploy(namespace: 'development', deploymentConfig: 'myapp') 6 | openshiftScale(namespace: 'development', deploymentConfig: 'myapp',replicaCount: '2') 7 | stage 'deployInTesting' 8 | openshiftTag(namespace: 'development', sourceStream: 'myapp', sourceTag: 'latest', destinationStream: 'myapp', destinationTag: 'promoteToQA') 9 | openshiftDeploy(namespace: 'testing', deploymentConfig: 'myapp', ) 10 | openshiftScale(namespace: 'testing', deploymentConfig: 'myapp',replicaCount: '3') 11 | } 12 | -------------------------------------------------------------------------------- /pipeline.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: BuildConfig 3 | metadata: 4 | name: myfirstpipeline 5 | labels: 6 | name: myfirstpipeline 7 | annotations: 8 | pipeline.alpha.openshift.io/uses: '[{"name": "myphp", "namespace": "", "kind": "DeploymentConfig"}]' 9 | spec: 10 | triggers: 11 | - 12 | type: GitHub 13 | github: 14 | secret: secret101 15 | - 16 | type: Generic 17 | generic: 18 | secret: secret101 19 | runPolicy: Serial 20 | source: 21 | type: None 22 | strategy: 23 | type: JenkinsPipeline 24 | jenkinsPipelineStrategy: 25 | jenkinsfile: "node() {\nstage 'build'\nopenshiftBuild(buildConfig: 'myphp', showBuildLogs: 'true')\nstage 'deploy'\nopenshiftDeploy(deploymentConfig: 'myphp')\nopenshiftScale(deploymentConfig: 'myphp',replicaCount: '2')\n}" 26 | output: 27 | resources: 28 | postCommit: 29 | -------------------------------------------------------------------------------- /pipelines example.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VeerMuchandi/pipeline-example/eae15ba389bc0da146eb95f17bbb5a393b2cb966/pipelines example.tiff -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## Creating your own pipeline 2 | 3 | 4 | ### Video 1: Creating your own pipeline 5 | 6 | The build configuration used for creating the pipeline is 7 | [https://github.com/VeerMuchandi/pipeline-example/blob/master/pipeline.yml]() 8 | 9 | 10 | 11 | ### Video 2: Edit the pipeline to deploy across projects 12 | 13 | The initial Jenkinsfile is [https://github.com/VeerMuchandi/pipeline-example/blob/master/Jenkinsfile1.txt]() 14 | 15 | The edited Jenkinsfile is [https://github.com/VeerMuchandi/pipeline-example/blob/master/Jenkinsfile2.txt]() 16 | 17 | 18 | In this example, the pipeline runs in the CICD Project. We will build and deploy an application first in a project named 'Development'. Later we will push the image created into a project named 'Testing'. 19 | 20 | ![](pipelines_example.tiff) 21 | 22 | 23 | Here are the commands I used from the OpenShift CLI: 24 | 25 | Creating a `development` Project and to provide `edit` access to the `jenkins` service account in the `development` project. 26 | 27 | ``` 28 | oc new-project development 29 | 30 | oc policy add-role-to-user edit system:serviceaccount:cicd:jenkins -n development 31 | ``` 32 | 33 | Creating a `testing` Project . Provide `edit` access to the `jenkins` service account in the `testing` project. Then provide `image-puller` access, so that `testing` project can pull an image from the `development` project. 34 | 35 | ``` 36 | oc new-project testing 37 | 38 | oc policy add-role-to-user edit system:serviceaccount:cicd:jenkins -n testing 39 | 40 | oc policy add-role-to-group system:image-puller system:serviceaccounts:testing -n development 41 | ``` 42 | 43 | To create a deployment configuration in the `testing` project that points to the image from development project, create a service and route: 44 | 45 | ``` 46 | oc create deploymentconfig myapp --image=<>:5000/development/myapp:promoteToQA 47 | 48 | oc expose dc myapp --port=8080 49 | 50 | oc expose svc myapp 51 | 52 | ``` 53 | 54 | 55 | --------------------------------------------------------------------------------