Jenkins

Plugins

Before you do anything make sure you have installed the plugins for the particular git repo you are working.

GitHub Integration

It's not as simple as the Bitbucket integration.

Go to Jenkins/configuration then scroll down to GitHub

  1. add the default Github server "https://api.github.com" no credentials and give it a decent name
  2. Click on the  Advanced...
  3. Check the "Override Hook URL" and get the webhook for github

Project using Github

Freestyle project

Make sure you select Git in the Source Control Management section

Pipeline project

Build Triggers



Projects using Bitbucket

Make sure you install the Bitbucket plugin

Freestyle project

In any project make sure the following are set


Git repo webhooks

Bitbucket

Simply go to your Settings / Webhooks and add a webhook - <the URL to Jenkins>/bitbucket-hook/

Make sure the url ends with /.

GitHub

Goto Settings / Integrations & Services / Add services / Jenkins (Github plugin)


Specify the webhook

The save/update the service





Script to build in a pipeline

build script
node 
{
   // Mark the code checkout 'stage'....
   stage 'Checkout'

   // Get some code from a GitHub repository
   withCredentials([usernamePassword(credentialsId: 'b0dab3e6-22ae-4db4-a7fd-5dd417a64a6c', passwordVariable: 'myLord43in43@ccan', usernameVariable: 'swright@celestial.co.uk')])
   {
       //git url: 'https://bitbucket.org/stream2stream/loginmanager/'
      
       checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'b0dab3e6-22ae-4db4-a7fd-5dd417a64a6c', url: 'https://stream2stream@bitbucket.org/stream2stream/loginmanager.git']]])
   
       // Get the maven tool.
       // ** NOTE: This 'M3' maven tool must be configured
       // **       in the global configuration.           
       //def mvnHome = tool 'M3'
    
       // Mark the code build 'stage'....
       stage 'Build'
       // Run the maven build
       //sh "${mvnhome}/bin/mvn clean install"
       sh "/bin/mvn clean package"
       sh 'cp target/LoginManager-1.0.war target/LoginManager.war'
       sh 'mv target/LoginManager.war /var/jenkins_home/workspace/"Deploy Login Manager"/'

   }
}