How to invoke a Jenkins build from Assembla on GIT push
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:

  1. You must have an assembla account with admin privilege.
  2. An external server with jenkins install
  3. Optional is artifactory
Assembla Configuration:
  1. Login to Assembla
  2. Click the Admin tab
  3. In the Tools section, click More in the far right side
  4. Find Webhook and click add
  5. In Webhook, enter the following settings:
    1. Title=Anything
    2. Enabled=true
    3. Authentication type=basic
    4. External url=http:///git/notifyCommit?url=%{repository_url}&branch=%{branch}
    5. Http method=GET
    6. Context type=text/plain
    7. Post updates about=check "Code Commits"
    8. Click Save
Jenkins Configuration:
  1. Login to Jenkins and make sure you have the following plugins installed:
    1. Jenkins Artifactory Plugin
    2. Jenkins GIT Plugin
    3. SSH Agent Plugin
    4. SSH Credential Plugin
    5. Maven Project Plugin
  2. Configure credentials
    1. Go to Jenkins->Manage Jenkins->Manage Credentials
      1. If you don't have a domain yet, click Add Domain
      2. Scope=Global
      3. Username=jenkins
      4. Private Key=From the Jenkins master ~/.ssh
      5. Click advance tab and enter your passphrase
Create a Job in Jenkins
  1. Click New Job
  2. Select Build a maven2/3 project
  3. Then fill up these fields, the rest can be filled with any values
    1. Source Code Management=GIT
    2. Repository URL=Copy your URL from Assembla, must be in this format: [email protected]:YOUR_PROJECT.git
    3. Advance->Name=origin
    4. Branches to build=master
    5. Build Triggers (checked)
      1. Build whenever a SNAPSHOT dependency is built
      2. Poll SCM - leave schedule field blank
    6. Root pom=eg YOUR_PROJECT/pom.xml
    7. Goal options=clean install OR install
    8. Build Environment (checked)
      1. SSH agent (select jenkins)
    9. Post-build Actions
      1. Deploy artifacts to artifactory
        1. Select your artifactory server
        2. Target release=libs-release-local
        3. Target Snapshot=libs-snapshot-local
        4. Deploy maven artifacts (checked)
        5. 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.
  1. Create a new file in ~/.profile
    1. In bash type: vi ~/.profile
    2. Press :qw
    3. Press: Enter
  2. 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:
  1. Create a key
  2. ssh-keygen -t dsa it will be created to /var/lib/jenkins/.ssh
  3. You will need to upload this key to assembla
Git Configuration
  1. You need to execute the 2 lines below to configure git, email must be the email you use in assembla
  2. git config —global user.name “Your Name”
  3. git config —global user.email “[email protected]
Testing
  1. In Ubuntu call execute: curl http:///git/[email protected]:.git&branches=master
  2. Go to jenkins job and look at Git Poll log, if something is wrong you will encounter Common Problem #1
Common Problems
  1. Permission Error
    1. status code 128:
    2. stdout: 
    3. stderr: Permission denied (publickey).
    4. fatal: The remote end hung up unexpectedly
    5. 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








.