#!/bin/bash # Script for GStreamer Jenkins CI # start : default branch # build branch : jenkins-build-branch # Create a new repo manifest file based on the default one, but containing # the current git revision of all used projects. The new manifest is meant # to be used for tracking the code used during each Jenkins build. # The new manifest is tagged with the build number and pushed to a git branch. # param: - Jenkins build number for the current job # Important: repo sync should have been done before # Build branch where new manifest will be stored if [ -z $BUILD_BRANCH ]; then BUILD_BRANCH=jenkins-build-branch fi if [ -z $BUILD_PREFIX ]; then BUILD_PREFIX= else BUILD_PREFIX+="_" fi # The default manifest file name MANIFEST_FILENAME=default.xml # Temporary file used to store the new manifest TMP_M_FILENAME=`mktemp --suffix=.xml` if [ -z $WORKSPACE ]; then echo "Out-of-jenkins build" if [ $# = 0 ]; then echo "Usage: $0 " exit 42 fi BUILD_ID=$1 fi if [ ! -d ".repo" ]; then echo "Cannot find a repo directory. Aborting..." exit fi echo echo "======================================================" echo # Gets the current repo root dir ROOT_DIR=`pwd` echo "Generating new manifest file for BUILD_ID $BUILD_ID [$BUILD_PREFIX]" # Create new manifest with all revisions repo manifest -r -o $TMP_M_FILENAME # Change to build branch and add the new manifest cd $ROOT_DIR/.repo/manifests git checkout $BUILD_BRANCH cp $TMP_M_FILENAME $MANIFEST_FILENAME # Remove temporary file rm -fr $TMP_M_FILENAME # Temporary file used to store the new changes for commiting TMP_C_FILENAME=`mktemp --suffix=.msg` # Store changes for commiting git diff --exit-code $MANIFEST_FILENAME > $TMP_C_FILENAME # Check if there's something new to commit if [ $? = 1 ]; then # Commit new manifest file git commit -F $TMP_C_FILENAME -- $MANIFEST_FILENAME || true echo "Tagging manifest for storage." # Tag the new manifest version CUR_DATE=`date +%Y%m%d` git tag -a "build_${BUILD_PREFIX}$BUILD_ID" \ -m "Tagging manifest build $BUILD_ID" echo "Pushing new manifest to the branch $BUILD_BRANCH" # Push new manifest to the build branch git push -v --tags origin $BUILD_BRANCH else echo "No changes to push" fi # Remove temporary file rm -fr $TMP_C_FILENAME # Move back to the default branch git checkout default # Go back to the root directory cd $ROOT_DIR echo echo "Done." echo "======================================================"