How to invoke a Jenkins build from Assembla on GIT push
This tutorial will try to configure a jenkins job to run when a git push is done on Assembla. This tutorial assumes that your server is ru...
https://www.czetsuyatech.com/2013/08/jenkins-trigger-build-on-git-push.html
This tutorial will try to configure a jenkins job to run when a git push is done on Assembla.
This tutorial assumes that your server is running in Ubuntu 12.04.2.
Requirements:
This tutorial assumes that your server is running in Ubuntu 12.04.2.
Requirements:
- You must have an assembla account with admin privilege.
- An external server with jenkins install
- Optional is artifactory
Assembla Configuration:
- Login to Assembla
- Click the Admin tab
- In the Tools section, click More in the far right side
- Find Webhook and click add
- In Webhook, enter the following settings:
- Title=Anything
- Enabled=true
- Authentication type=basic
- External url=http://
/git/notifyCommit?url=%{repository_url}&branch=%{branch} - Http method=GET
- Context type=text/plain
- Post updates about=check "Code Commits"
- Click Save
Jenkins Configuration:
- Login to Jenkins and make sure you have the following plugins installed:
- Jenkins Artifactory Plugin
- Jenkins GIT Plugin
- SSH Agent Plugin
- SSH Credential Plugin
- Maven Project Plugin
- Configure credentials
- Go to Jenkins->Manage Jenkins->Manage Credentials
- If you don't have a domain yet, click Add Domain
- Scope=Global
- Username=jenkins
- Private Key=From the Jenkins master ~/.ssh
- Click advance tab and enter your passphrase
Create a Job in Jenkins
- Click New Job
- Select Build a maven2/3 project
- Then fill up these fields, the rest can be filled with any values
- Source Code Management=GIT
- Repository URL=Copy your URL from Assembla, must be in this format: git@git.assembla.com:YOUR_PROJECT.git
- Advance->Name=origin
- Branches to build=master
- Build Triggers (checked)
- Build whenever a SNAPSHOT dependency is built
- Poll SCM - leave schedule field blank
- Root pom=eg YOUR_PROJECT/pom.xml
- Goal options=clean install OR install
- Build Environment (checked)
- SSH agent (select jenkins)
- Post-build Actions
- Deploy artifacts to artifactory
- Select your artifactory server
- Target release=libs-release-local
- Target Snapshot=libs-snapshot-local
- Deploy maven artifacts (checked)
- Capture and publish build info (checked)
Configure your SSH Agent
*NOTE: This script is not mine, I got it somewhere on google on OSX related forum unfortunately I forgot the link and can't find it now. Basically you need to add a new file for Ubuntu's jenkins user.
- Create a new file in ~/.profile
- In bash type: vi ~/.profile
- Press :qw
- Press: Enter
- Paste the following lines (ssh-agent need to be set before invoking ssh-add):
# Note: ~/.ssh/environment should not be used, as it already has a different purpose in SSH. env=~/.ssh/agent.env # Note: Don't bother checking SSH_AGENT_PID. It's not used # by SSH itself, and it might even be incorrect # (for example, when using agent-forwarding over SSH). agent_is_running() { if [ "$SSH_AUTH_SOCK" ]; then # ssh-add returns: # 0 = agent running, has keys # 1 = agent running, no keys # 2 = agent not running ssh-add -l >/dev/null 2>&1 || [ $? -eq 1 ] else false fi } agent_has_keys() { ssh-add -l >/dev/null 2>&1 } agent_load_env() { . "$env" >/dev/null } agent_start() { (umask 077; ssh-agent >"$env") . "$env" >/dev/null } if ! agent_is_running; then agent_load_env fi if ! agent_is_running; then agent_start ssh-add elif ! agent_has_keys; then ssh-add fi unset env
How to create an SSH key:
- Create a key
- ssh-keygen -t dsa it will be created to /var/lib/jenkins/.ssh
- You will need to upload this key to assembla
Git Configuration
- You need to execute the 2 lines below to configure git, email must be the email you use in assembla
- git config —global user.name “Your Name”
- git config —global user.email “email@email.com”
Testing
- In Ubuntu call execute: curl http://
/git/notifyCommit?url=git@git.assembla.com: .git&branches=master - Go to jenkins job and look at Git Poll log, if something is wrong you will encounter Common Problem #1
Common Problems
- Permission Error
- status code 128:
- stdout:
- stderr: Permission denied (publickey).
- fatal: The remote end hung up unexpectedly
- Solution: Your key is not properly setup either on jenkins or profile bash file
Post a Comment