The Jenkinsfile in this repository contains a sample pipeline that performs a build and applies object configurations to instantiate this application.
The pipeline can be used to maintain a running application on an OpenShift cluster.
-
Start an OpenShift cluster (origin v1.3 and later). Create a new project.
-
[Optional] Create a fork of this repository
-
Instantiate the pipeline from template by invoking: (Where FORK is your own fork of this repository or
openshift-roadshow
)oc new-app -f https://raw.githubusercontent.com/FORK/nationalparks/master/ose3/pipeline-buildconfig-template.json -p GIT_URI=https://github.com/FORK/nationalparks.git
-
Start the pipeline build from the CLI with:
oc start-build nationalparks-pipeline
OR
Start the pipeline from the web console. Navigate to the project, Builds->Pipelines. Click
Start
next to the nationalparks-pipeline.
The Jenkinsfile in this repository can be used to support a PR flow with Jenkins on OpenShift. The main application is built and deployed to an 'integration' project. Every time a PR is submitted to the source repository, a new OpenShift project is created to build and test the PR and allow for manual testing. Once the manual testing is approved, the build succeeds.
The following steps guide you through the setup of the Github Organization Folder plugin in Jenkins and the required steps on the GitHub side. The Github Organization Folder plugin instantiates a pipeline for every project it finds with a Jenkinsfile at its root. It also sets up webhooks in GitHub so that new PRs and changes to a branch are automatically built in Jenkins. In order for webhooks to work, the ngrok application is used to create a public endpoint for the internal Jenkins service.
- Create your own forks of nationalparks, mlbparks, and parksmap-web.
- Create a GitHub personal access token
with access to
repo
,admin:repo_hook
,admin:org_hook
. (Keep your token to use below as GITHUB-TOKEN).
-
Create a new project:
oc new-project PROJECT-NAME
-
Assign the right permission to your jenkins service account:
- Login as system administrator. If running cluster up:
oc login -u system:admin
- Apply the self-provisioner role to your jenkins service account (Substitute PROJECT-NAME with the name of the project you created above):
oc adm policy add-cluster-role-to-user self-provisioner system:service-account:PROJECT-NAME:jenkins
- Log back in as a regular user. If using cluster up:
oc login -u developer
-
Add Jenkins to your project:
oc new-app openshift/jenkins-ephemeral -p MEMORY_LIMIT=1Gi
-
[Optional] If your cluster is not externally accessible (if for example, you started it locally with
cluster up
):-
Expose the jenkins service externally (for GitHub webhooks) with ngrok:
oc new-app -f https://raw.githubusercontent.com/csrwng/ngrok/master/openshift/ngrok-template.yaml -p HOST=jenkins -p PORT=80
-
Get public webhook URL from ngrok:
-
Navigate to the ngrok application using the route created by the ngrok template:
oc get route ngrok
-
The main page will display 2 URLs. Copy either URL to use for your Jenkins webhook.
-
-
Configure the Github webhook URL on Jenkins
-
Login to Jenkins
-
Go to Manage Jenkins -> Configure System
-
Under GitHub section:
- Click on the
Advanced...
button - Check
Specify another hook url for GitHub configuration
- Replace the default URL host with the one from ngrok (url should look something like: http://47e8e09b.ngrok.io/github-webhook/)
- Click on the
-
Click on
Save
at the bottom of the screen.
-
-
-
Configure Github Server on Jenkins
-
Login to Jenkins
-
Go to Manage Jenkins -> Configure System
-
Under GitHub section:
- Click on
Add Github Server
and selectGitHub Server
- Click on
Add
next toCredentials
and selectJenkins
- Leave
Kind
asUsername with password
. ForUsername
enter your GitHub username, forPassword
enter your GITHUB-TOKEN, click onAdd
- Click on
Add
again (as in step b) - Select a
Kind
ofSecret text
. ForSecret
paste your GITHUB-TOKEN, and forDescription
enter descriptive text likeGithub Token
, click onAdd
- Under the
Credentials
dropdown, select the one you just created. - Click on
Test connection
- Click on
-
Click on
Save
at the bottom of the screen.
-
-
Add Github Organization Plugin
- Click on Manage Jenkins -> Manage Plugins -> Available
- In the
Filter
search box, entergithub organization
- Check the box next to
GitHub Organization Folder Plugin
- Click on
Download now and install after restart
- Check the checkbox next to
Restart Jenkins when installation is complete and no jobs are running
- Log back in to Jenkins and navigate to the Home screen by clicking on
Jenkins
in the top left of the window
-
Add the organization
- Click on
New Item
- Enter a name for your organization project
- Select
Github Organization
and clickOK
- Under
Project Sources
->Github Organization
- For
Owner
enter your GitHub username - For Scan credentials, select the credentials you created earlier.
- For repository name pattern, enter a pattern that includes the repositories you forked earlier:
(parksmap-web|nationalparks|mlbparks)
- For
- Click on
Save
at the bottom
- Click on
Once Jenkins instantiates the pipelines under the Organization folder, a build will be started for
each repository found by the plugin. Their corresponding OpenShift artifacts will be instantiated
in the same project as Jenkins. This will contain the master
branch of each project. Each new PR
to each repository will result in a new pipeline getting instantiated and a new project getting created
for that pipeline. The GitHub PR will then include a status of the build, a link to the application preview,
and a link to the approval page.