Build Jenkins docker image with needed tools for ChatOps project:
- nodejs + npm
- coffee-script
- mocha
- jshint
- coffeelint
- Github account (github.com or enterprise)
- Github project with pipeline (from https://github.com/eedevops/he-jenkins-ci)
- (optional) slack account
- Host: Docker installed and fully configured
- Verify that you can manage the organization that you want to make CI for
- on github, go to your profile
settings
- "Personal access tokens"
- "Generate new token"
- give token description
- Select all
repo
scopes - Click "Generate token" and save the token on your computer
- Create slack team (https://slack.com/)
- In slack chat ui click on the team name(top left)
- Click on "Apps and Integrations"
- Search for "Jenkins CI" app
- Follow the wizard to add the app
- Write down app API token, your team name, and rooms jenkins will report to
docker pull chatopshpe/jenkins-chatops
- First run (or run without local jenkins folder)
- (optional) create folder for jenkins to store data
- create jenkins user
sudo adduser jenkins
- chown the folder to user jenkins
```bash
sudo chmod g+s <LOCAL_DIR>
sudo chown -R jenkins: <LOCAL_DIR>
```
- get jenkins group id
id jenkins
- run (replace
${*}
with real values):
```bash
docker run -p 80:9090 -p 50000:50000 -v <LOCAL_DIR>:/var/jenkins_home -u :<GID> \
-e "ADMIN_PW=<ADMIN_PW>" \
-e "GH_TOKEN=<GH_TOKEN>" \
-e "GHE_TOKEN=<GHE_TOKEN>" \
-e "GIT_KEY=$(cat ~/.ssh/id_rsa)" \
-e "SLACK_CONF=<TEAM>|<TOKEN>|<ROOMS>" \
-e "http_proxy=$http_proxy" -e "https_proxy=$http_proxy" \
-e "no_proxy=$no_proxy" \
-e "ORGANIZATION=<ORG_OR_USERNAME}><^+ENTERPRISE_URL>" \
-e 'REGEX=<REGEX>' -e "HOST=http://<HOSTNAME||IP>:<PORT_IF_NOT_80>" \
-e JAVA_OPTS="-Dhttp.proxyHost=<proxy_host without http[s]:// prefix> -Dhttp.proxyPort=<proxy_port> -Dhttps.proxyHost=<proxy_host without http[s]:// prefix> -Dhttps.proxyPort=<proxy_port>" \
jenkins-chatops
```
example:
```bash
docker run -p 80:9090 -p 50000:50000 -v /data/jenkins:/var/jenkins_home -u :105 \
-e "ADMIN_PW=123" \
-e "GH_TOKEN=dlkfajhslkfjh" \
-e "GHE_TOKEN=jdglmnmnbdajhdg"
-e "GIT_KEY=$(cat ~/.ssh/id_rsa)" \
-e "SLACK_CONF=myteam|xox-fkjhjhk|#general" \
-e "http_proxy=$http_proxy" -e "https_proxy=$http_proxy" \
-e "no_proxy=$no_proxy" \
-e "ORGANIZATION=myOrg^github.myorg.org" \
-e 'REGEX=hubot-.*' -e "HOST=http://myserver.acme.com" \
-e JAVA_OPTS="-Dhttp.proxyHost=<proxy_host without http[s]:// prefix> -Dhttp.proxyPort=<proxy_port> -Dhttps.proxyHost=<proxy_host without http[s]:// prefix> -Dhttps.proxyPort=<proxy_port>" \
jenkins-chatops
```
- (if using local folder) log in to jenkins server with
admin
username and provided password and stop the docker image - (if using local folder) run image without secret variables:
```bash
docker run -p 80:9090 -p 50000:50000 \
-v <LOCAL_DIR>:/var/jenkins_home \
-e "http_proxy=$http_proxy" -e "https_proxy=$http_proxy" \
-e JAVA_OPTS="-Dhttp.proxyHost=<proxy_host without http[s]:// prefix> -Dhttp.proxyPort=<proxy_port> -Dhttps.proxyHost=<proxy_host without http[s]:// prefix> -Dhttps.proxyPort=<proxy_port>" \
-u :<GID> jenkins-chatops
```
- edit
init.d/jenkins-docker
file to change the following params (if needed)
JENKINS_NAME=jenkins-master
- `DATA_DIR="<LOCAL_DIR>"``
- `DOCKER_IMAGE="jenkins_chatops"``
PORT=80
DOCKER_PORT=9090
SLAVE_PORT=50000
GROUP_ID=<JENKINS_GROUP_ID>
group id jenkins data folder belongs to (id <username>
)- `RESTART_OPT="--restart=always"``
sudo cp init.d/jenkins-docker /etc/init.d/
sudo chmod +x /etc/init.d/jenkins-docker
- manage service using
sudo service jenkins-docker start/stop/status
- plugins
- skip setup wizard
- 5 executors
- credentials for pipeline (github-token, github-enterprise-token, github-ssh)
- created if passed
GH_TOKEN
,GHE_TOKEN
,GIT_KEY
, default isPLACEHOLDER
- Create admin user, default password 'admin' unless
ADMIN_PW
env var passed - Github enterprise endpoint creation if
^enterprise.url
passed inORGANIZATION
env var - Slack notifications configuration if
SLACK_CONF
passed - proxy auto setup (if
http_proxy
env var is set) - set jenkins root url if
HOST
env var is set - create github organization folder if
ORGANIZATION
env var passed
- run
sudo ./build.sh
to build the docker image
- Download and install bats testing framework: https://github.com/sstephenson/bats
- run
bats tests/tests.bat
Currently jenkins-chatops support slack platform, other platforms might be added later on.