Source Code Management
- Configure you job to use a
git repository
at
- The source code will be cloned to the
workspace
. The workspace is inside the jenkins_home folder and has the same name as the job name
Git Server
docker run --detach \
--name "gitlab" \
--hostname "gitlab.example.com" \
--publish "8090:80" \
--network "bridge" \
--restart "always" \
--volume "$HOME/gitlab_home/config:/etc/gitlab" \
--volume "$HOME/gitlab_home/logs:/var/log/gitlab" \
--volume "$HOME/gitlab_home/data:/var/opt/gitlab" \
"gitlab/gitlab-ee:latest"
echo -n "127.0.0.1 gitlab.example.com" >> /etc/hosts
Git Hooks
- Git hooks example: if some code is pushed to master branch, then get a jenkins crumb
- Custom hooks must be placed inside of the git repository. E.g.,
custom_hooks
folder
#!/bin/bash
if ! [ -t 0 ]; then
read -a ref
fi
IFS='/' read -ra REF <<<"${ref[2]}"
branch="{REF[2]}"
if [ $branch == "master" ]; then
crumb=$(curl "http://localhost:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,':',//crumb)" -u "admin:123")
curl -X "POST" "http://localhost:8080/job/job-name/build?delay=0sec" -u "admin:123" -H "$crumb"
if [ $? -eq 0 ]; then
echo "*** OK"
else
echo "*** Error"
fi
fi