Tech-Today
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 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: [email protected]: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 protected]”
Testing
- In Ubuntu call execute: curl http:///git/[email protected]:.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
-
Install Jenkins On Ubuntu
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add - Then add the following entry in your /etc/apt/sources.list: deb https://pkg.jenkins.io/debian-stable binary/ sudo apt-get update sudo apt-get install jenkins sudo usermod...
-
Operating Systems
How to show all startup items in Ubuntu 12.04How to install artifactory and jenkins on ubuntu 12.04How to dual boot Windows 7 and Ubuntu 12.04 on Lenovo G480How to setup an OpenVPN client on an Ubuntu machineHow to setup a DNS Server on ubuntu 12.04How...
-
Repository Management
GITHow to invoke a Jenkins build from Assembla on GIT pushHow to initialize a git repository and linked it to a remote repository providerSVNHow to setup your google code repository to be accessible in mavenMAVENHow to push external jar into artifactory...
-
How To Install Artifactory And Jenkins On Ubuntu 12.04
This page is a summary of commands that need to be executed in order to install and setup artifactory and jenkins on Ubuntu 12.04. Install artifactory 1.) Download the zipped file from artifactory: >wget http://sourceforge.net/projects/artifactory/files/artifactory/2.6.4/artifactory-2.6.4.zip...
-
Could Not Resolve Dependencies For Project Com.xxxjar:-snapshot: Failed To Collect Dependencies For
I just have this weird problem using maven + artifactory. I have a project which I first build using maven-compiler 2.3.2, and maven2. It build successfully and I was able to deploy in artifatory 2.5. Eventually I've added several modules and one...
Tech-Today