- 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
- FAQ
- GitHub Account
- Hyper.sh Credential
- Hyper client
- Installed on localhost (it’s used to run Jenkins Server in Hyper.sh Cloud)
- Docker image
- hyperhq/hykins (pre-built Jenkins server image)
- hyper client
- GitHub Pull Request Builder Plugin
- Hyper.sh Slaves Plugin
- Other Recommended Plugin(git, ssh-slaves, credentials-binding, gradle,...)
- hyperhq/hykins (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/hykins
//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.sh Config
-> Input "Hyper.sh Access Key" and "Hyper.sh Secret Key"
-> Click "Save Credentials" button
-> Click "Test connection to Hyper.sh" 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.sh 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] Trigger Build PR manually
- 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.
This will occur when use EIP as Jenkins URL.
To solve this issue, Please use internal ip(default) as "Jenkins URL".
And use EIP in "Jenkins URL override" of "GitHub Pull Request Builder"
The Commit Status URL
will be JENKINS URL
by default.
For Hykins, the JENKINS URL
will be private ip by default.
To customize the url in github, please set the Commit Status URL
in job configuration:
Build Triggers -> GitHub Pull Request Builder -> Trigger Setup -> Update commit status during build
-> Commit Status Context
-> Commit Status URL
Commit Status URL
example:
//x.x.x.x could be public ip or a domain.
http://x.x.x.x:8080/job/${JOB_NAME}/${BUILD_NUMBER}
Note: Not the following config item
Build Environment -> Set GitHub commit status with custom context and message (Must configure upstream job using GHPRB trigger)