Jenkins
Introduction
We at Stakater use Jenkins as our continuous integration, continuous development and continuous testing server. Jenkins is a self-contained, open source automation server which can be used to automate all sorts of tasks related to building, testing, and delivering or deploying software.
Chart
We use public helm charts to deploy jenkins on our cluster. Here is the public chart that we use and 0.23.0
is the public chart version that is used in our cluster. We use umbrella charts to deploy jenkins on our cluster. Currently we are using this repository for jenkins deployment.
Image
Currently we are using this jenkins/jenkins:2.159
public image for jenkins in stakater.
Cherry Pickable
Yes, Depends Only on keycloak for SSO
Single Sign-on
Yes, our jenkins setup supports SSO. We use jenkins open id connect to achieve this.
Installation
Installation Steps
- Most of the times Jenkins will be deployed manually and not via pipeline because jenkins is the entity that is used to run these pipelines.
- To install jenkins manually, you can run the make targets of repo containing latest used implementation of jenkins. This will install all dependencies and jenkins as well.
- Verify from UI that jenkins pod is running and accessible.
Post-Installation-Configurations
Configuration is divided into three parts:
- Jenkins own configuration,
- Github configuration and
- Gitlab configuration.
Jenkins Configurations
- Go to
Manage Jenkins
on left navigation bar. Select the first optionConfigure System
- Update the
Cloud -> Kubernetes -> Kubernetes Pod Template -> Advance
and empty theLimit CPU
andLimit Memory
fields. - Update the
Cloud -> Kubernetes -> Kubernetes Pod Template ->
- Name: base
- Labels: base
- Update
# of executors
to 5 - Update
Usage
toOnly build jobs with label expressions matching this node
Github Configurations
- Go to
Manage Jenkins
on left navigation bar. Select the first optionConfigure System
- Update
GitHub -> GitHub Server
(Use Add GitHub Server if not added already)- Name: Github
- API URL: https://api.github.com
- Credentials: Generate new github credentials of
stakater-user
or reuse existing credentials. And use these as secret-text in jenkins credentials.- Add Credentials with kind Secret Text
- Secret: testsecret (Or get new one from teamlead)
- ID: GithubToken
- Save and use this credential.
- Test connection. It should be successful.
- Click on
Advance
and use gitwebhookproxyurl forOverride Hook URL
e.g. https://gitwebhookproxy.tools.stackator.com/github-webhook/ - Use the secret that is being used in github repos for webhook authentication for Shared secret. e.g.
testsecret
- Add Credentials with kind
Secret Text
- Secret: testsecret (Or get new one from teamlead)
- ID: DummySecret
- Save and use this credential.
- Add Credentials with kind
- Make sure this secret is same for github, gitwebhookproxy and jenkins.
Steps to Create Github Organizations
- Click on
New Item
on left navigation bar. - Enter an item name and select
Github Organization
and click ok. - Enter the Display name. E.g. Stakater
- Select Credentials
- Enter Owner. It is the name of github organization. Make sure it is in small case.
- Update
Discover pull requests from forks -> Trust -> Contributors
- Check
Periodically if not otherwise run
and uncheck/disable it. - Enter
Automatic branch project triggering -> Branch names to build automatically PR
(This is a random regex to avoid triggering all webhook) - Click apply and then save. It should automatically start scanning the repos. If it doesn’t start then manually start scanning the organization by clicking the
Scan Organization Now
button on left navigation bar.
Organizations
Steps to Create Github Organizations are same for every github organization. After the scan is complete, follow update these values in each organization to complete the setup.
Stakater:
Owner: stakater
Filter by name (with regular expression): ([A-Z][a-z0-9]+)+
Branch names to build automatically: (PR-\d+|master)
Stackator Input:
Owner: stakater
Filter by name (with regular expression): [\w-]*input\b|^stackator-[\w-]*|^stakater-[\w-]*
Branch names to build automatically: (PR-\d+|master)
Stakater Charts:
Owner: stakater-charts
Branch names to build automatically: (PR-\d+|master)
Stakater Docker:
Owner: stakater-docker
Branch names to build automatically: (PR-\d+|master)
Stakater Lab:
Owner: stakater-lab
Branch names to build automatically: (PR-\d+|master)
Gitlab Configurations
- Go to
Manage Jenkins
on left navigation bar. Select the first optionConfigure System
- Uncheck
Enable authentication for '/project' end-point
- Update
Gitlab -> GitLab connections
- Connection name: gitlab
- Gitlab host URL: https://gitlab.com/
- Credentials: Create gitlab token and use that token as GitLab API token while creating credentials
- Token: testToken (Get Latest token from teamlead)
- Test Connection. It should be successful.
- Go to
Manage Jenkins
on left navigation bar. Select the second optionConfigure Global security
- Uncheck
CSRF Protection -> Enable script security for Job DSL scripts
Steps to Create Gitlab Organizations
- Click on
New Item
on left navigation bar. - Enter an item name and select
Multibranch Pipeline
and click ok. Name of item should be as same as given in its gitlab webhook url ie. carbook-gitlab-config - Enter the Display name. E.g. carbook-gitlab-config
- Update
Branch Sources -> Git
- Project Repository: https://gitlab.com/carbook/carbook-gitlab-config
- Credentials: Create jenkins username with password credentials and use
carbook.bot
as username and ID. Get password from team lead.
- Save and apply the changes.
- Trigger master branch and it will automatically create remaining gitlab pipelines.
- Scan manual pipelines so their branches get discovered
Dependencies
Below are the dependencies of jenkins. PRs have been created for all these dependencies in public helms chart repository but we are waiting for the approval. storage
, secrets
, rbac
, configmap
are helper charts that are used in conjunction with Jenkins chart because jenkins does not provide support for addition storage, secret, rbac and configmap. We need to deploy these dependencies with jenkins.
- name: storage
version: 1.0.1
repository: https://stakater.github.io/stakater-charts/
alias: mvnstorage
- name: secrets
version: 1.0.2
repository: https://stakater.github.io/stakater-charts/
alias: secrets
- name: rbac
version: 1.0.1
repository: https://stakater.github.io/stakater-charts/
alias: rbac
- name: configmap
version: 1.0.1
repository: https://stakater.github.io/stakater-charts/
alias: configmap
- name: xposer
version: 0.0.3
repository: https://stakater.github.io/stakater-charts/
alias: xposer
- name: restful-distributed-lock-manager
version: 1.0.2
repository: https://stakater.github.io/stakater-charts/
alias: restful-distributed-lock-manager
Hard-coded-values
Below are hard coded values for Jenkins and it's dependencies. NOTE All credentials used here are not real. Please get the latest credentials before using these hard coded values.
configmap values
Update the external-docker-registry-url and set it’s value equals to the docker repository url attached with nexus.
external-docker-registry-url: docker.release.stakater.com:443
xposer values
Update the domain and set it’s value equals to the your domain
domain: stakater.com
secrets values
- Update this
jenkins-docker-cfg
secret and update the data inconfig.json
containing docker repository url of nexus. - Update this
jenkins-maven-settings
secret and update the data insettings.xml
containing docker repository url of nexus. - Update this
docker-registry-secret
secret and update the data in.dockercfg
containing docker repository url of nexus. - Update this
k8s-current-cluster-kubeconfig
secret and update the data inconfig
containing the kube config of cluster.
Jenkins values
Update below values in Jenkins chart.
- Update the storage class name
jenkins:
Persistence:
Enabled: true
StorageClass: efs
- Update the HostName value
jenkins:
Master:
HostName: jenkins.release.stakater.com
- Update the ingress annotations and TLS host name
jenkins:
Master:
Ingress:
Annotations:
ingress.kubernetes.io/force-ssl-redirect: "true"
kubernetes.io/ingress.class: external-ingress
ingress.kubernetes.io/proxy-body-size: 150m
forecastle.stakater.com/expose: "true"
forecastle.stakater.com/icon: https://github.com/stakater/ForecastleIcons/raw/master/jenkins.png
TLS:
- hosts:
- jenkins.release.stakater.com
- Update the keyclaok realm settings. Get the
clientSecret
from team lead.
jenkins:
Master:
SecurityRealm: |-
<securityRealm class="org.jenkinsci.plugins.oic.OicSecurityRealm" plugin="oic-auth@1.0">
<clientId>stakater-online-platform</clientId>
<clientSecret>testsecret</clientSecret>
<tokenServerUrl>https://keycloak.release.stakater.com/auth/realms/stakater/protocol/openid-connect/token</tokenServerUrl>
<authorizationServerUrl>https://keycloak.release.stakater.com/auth/realms/stakater/protocol/openid-connect/auth</authorizationServerUrl>
<userNameField>email</userNameField>
<scopes>openid email</scopes>
</securityRealm>
Plugins
Below is the list of plugins needed for Jenkins to work properly. Add these under InstallPlugins
in values.yaml
- git:3.9.1
- oic-auth:1.4
- github:1.29.2
- github-pullrequest:0.2.4
- github-oauth:0.29
- github-api:1.92
- github-branch-source:2.4.1
- github-issues:1.2.4
- workflow-multibranch:2.20
- pipeline-model-api:1.3.2
- pipeline-stage-step:2.3
- workflow-cps-global-lib:2.11
- pipeline-github-lib:1.0
- kubernetes:1.12.6
- kubernetes-pipeline-steps:1.5
- kubernetes-pipeline-aggregator:1.5
- workflow-basic-steps:2.11
- jdk-tool:1.1
- jackson2-api:2.8.11.3
- blueocean-pipeline-api-impl:1.8.4
- pipeline-utility-steps:2.1.0
- gitlab-plugin:1.5.10
- gitlab-merge-request-jenkins:2.0.0
- job-dsl:1.70
- cloudbees-folder:6.6
- authorize-project:1.3.0
- gitlab-hook:1.4.2
- pipeline-stage-view:2.10
- ssh-agent:1.17
- ssh:2.6.1
- ssh-credentials:1.14
- ssh-steps:1.1.1
- rich-text-publisher-plugin:1.4
- timestamper:1.8.10
Jobs
Below are the Jenkin Jobs that we use in stakater. Here is the procedure to configure these jobs.
carbook-gitlab-config = Multibranch Pipeline = Gitlab Pipeline
developer-handbook = Multibranch Pipeline = Github Pipeline
Stackator Input = Organization = Github Pipeline
Stakater = Organization = Github Pipeline
Stakater Charts = Organization = Github Pipeline
Stakater Docker = Organization = Github Pipeline
Stakater Lab = Organization = Github Pipeline
Credentials
- Gitlab
- gitlab token: Create gitlab token and use that token as GitLab API token while creating credentials in
Manage Jenkins
- carbook.bot: Create jenkins username with password credentials and use carbook.bot as username and credentials id. Get password from team lead. These credentials will be used when creating Multibranch Pipeline for gitlab
- gitlab token: Create gitlab token and use that token as GitLab API token while creating credentials in
- Github
- stakater-user: Generate new github credentials of stakater-user or reuse existing credentials. And use these as secret-text in jenkins credentials. These will be used while configuring github in Manage Jenkins
- testsecret: Use the secret that is being used in github repos for webhook authentication for Shared secret