Project

Profile

Help

How to build last commit by push

Prerequisite

Install jenkins prescm plugin https://wiki.jenkins-ci.org/display/JENKINS/pre-scm-buildstep
install jenkins Extended Choice Parameter plugin https://wiki.jenkins-ci.org/display/JENKINS/Extended+Choice+Parameter+plugin

Setup

  • Create github hook to trigger build remotely by any push
  • Create properties file with branches sorted by last commit with pre scm plugin
    git reset --hard;git clean -fxd;git pull --no-edit --all
    sorted_branches_path=$HOME/mdbci_jenkins_config/sorted_branches
    rm $sorted_branches_path
    for branch in $(git for-each-ref --sort=committerdate refs/remotes  --format='%(refname:short)'); do
        echo -e "$(echo $branch | awk -F'/' '{print $2}'),$(cat $sorted_branches_path)" > $sorted_branches_path
    done
    echo -e "branch_name=$(cat $sorted_branches_path)" > $sorted_branches_path
    

    with code above we can get file with content like:
    branch_name=branch_name_1,branch_name_2,branch_name_3,branch_name_4,....
    
  • Add choice parameter to build
  • Set Property Key to
    branch_name
  • Set Property File to path where you created file with sorted branches
  • Then after that part would be executed before scm step (or it would be done in other job), file with branches would be created it can be used with next code
    ... TODO