- 1.Summary
- 2.Run Jenkins Server
- 3. Access Jenkins Web UI
- 4.Config Jenkins
- 5.Config Job
- 6. Trigger Build by GitHub Webhook
- 7. Build Result
- 8 Problem
- GitHub Account
- Hyper_ Credential
- Hyper client
- Installed on localhost (it’s used to run Jenkins Server in Hyper_ Cloud)
- Docker image
- hyperhq/hyperkins (pre-built Jenkins server image)
- hyper client
- GitHub Pull Request Builder Plugin
- Hyper_ Slaves Plugin
- Other Recommended Plugin(git, ssh-slaves, credentials-binding, gradle,...)
- hyperhq/hyperkins (pre-built Jenkins server image)
- Main repo(build PR)
- Cloned repo(create PR)
- Commit the change to cloned repo.
- Create PR via cloned repo.
- Jenkins job(for Main Repo) will be triggered via GitHub Webhook.
- Jenkins build PR automatically.
- Jenkins will set build status of PR on GitHub.
//start Jenkins Server container
$ hyper run --name jenkins-server \
-d -P \
-v jenkins-data:/var/jenkins_home \
hyperhq/hyperkins
//add public ip to container
$ FIP=$(hyper fip allocate 1)
$ hyper fip attach $FIP jenkins-server
Open http://$FIP:8080
in Web Browser.
The default admin account is admin
/nimda
.
If you want to customize the admin account, please see this
(Menu) Manage Jenkins -> Configure System -> Hyper Config
-> Input "Hyper_ Access Key" and "Hyper_ Secret Key"
-> Click "Save credential" button
-> Click "Test connection to Hyper_" button
(Menu) Manage Jenkins -> Configure System -> GitHub Pull Request Builder
-> Click "Create API Token" button
-> Input "Username temp" and "Password temp" (GitHub account to create token)
-> Click "Create Token" button
-> Click global "Save" button of "Config System"
Goto https://github.com/settings/tokens.
A personal access token named Jenkins GitHub Pull Request Builder
will be created in GitHub.
This token is used to create GitHub Webhook and update status of each PR on GitHub
(Menu) Manage Jenkins -> Configure System -> GitHub Pull Request Builder
-> Shared secret : Secret of GitHub Webhook.
-> Credentials : Select GitHub auto generated token credentials.
Create a job of Freestyle project
.
- Check
Run the build inside Hyper_ container
- Docker Image
- hyperhq/jenkins-slave-golang:1.7-centos (Dockerfile)
- Docker Image
- GitHub project
- Project URL
Repository URL: https://github.com/Jimmy-Xu/example
Refspec:+refs/pull/*:refs/remotes/origin/pr/*
Branch Specifer:${sha1}
[Optional]
To build PR manually,just add a "String Parameter" like this:
- GitHub API credentials
- Be Configured in Jenkins global config
- Use GitHub Webhook for build triggering
- Trigger Build via GitHub Webhook
- This option will disable cron-based polling
- Whitelist
- People who submit pull requests can have their pull requests automatically build.
- If you don’t add people to the white list you will need to tell Jenkins to build the PR.
Add two build step:
- Set build status to
pending
on GitHub commit - Execute shell
set +x
START_TIME=$(date "+%F %T %z")
START_TS=$(date "+%s")
#################################
echo "------------------------------------------------" > result.txt
cat /proc/cpuinfo | grep -E '(processor|model name|cpu cores)' >> result.txt
echo "-------------------------------------" >> result.txt
cat /proc/meminfo | grep ^Mem >> result.txt
echo "-------------------------------------" >> result.txt
cat result.txt
#################################
echo "----- prepare -----"
export GOPATH=$WORKSPACE/../gopath
mkdir -p $GOPATH $GOPATH/src/github.com/golang
if [ ! -L $GOPATH/src/github.com/golang/example ];then
ln -s $WORKSPACE $GOPATH/src/github.com/golang/example
fi
echo "----- start unit test -----"
cd $WORKSPACE/stringutil
go test -v
echo "----- start compile -----"
cd $WORKSPACE/hello
go build
RLT=$(./hello)
if [ "$RLT" == "Hello, Go examples!" ];then #centos use bash
echo OK
else
echo Failed
exit 1
fi
echo "----- compress -----"
tar czvf hello.tar.gz hello
#################################
END_TIME=$(date "+%F %T %z")
END_TS=$(date "+%s")
echo "--------------------------------"
echo "Step Start Time:${START_TIME}"
echo "Step End Time:${END_TIME}"
echo "Step duration: $((END_TS-START_TS))"
After the above Jenkins Job was saved, a GitHub Webhook
will be created automatically.
(https://github.com/Jimmy-Xu/example/settings/hooks)
To build PR by GitHub Webhook:
- Commit the change to cloned repo https://github.com/cocobjcn/example .
- Create Pull Request in cloned repo. Then, Jenkins Job build will be triggered via GitHub Webhook automatically.
Note: For test purpose, you just need to create one Pull Request. You can Close and Re-Open the PR, then a new job build will be triggered again.
Jenkins will set build status of PR on GitHub.
Click the Details link will jump to Jenkins build history.