Jenkins pass a shell script variable to a down stream job

Viewed 14

I'm new to Jenkins.

I have a job with an "Execute Shell" Build trigger, and in that shell script i initiate some variables with values i take from some source.

I need to pass these values to a downstream job.

The values i want to pass are $IMG_NAME and $IMG_PATH from this shell script:

 #!/bin/bash -x

whoami

echo "BASE_PATH: $BASE_PATH"

declare -A BRANCHES

for i in $(echo $BRANCHES_LIST | tr ',' '\n'); do BRANCHES[$i]= ; done

echo 'user' | sudo -S umount -rf /mnt/tlv-s-comp-prod/drops/

echo 'user' | sudo -S mount.nfs -o nolock,nfsvers=3 tlv-s-comp-prod:/export/drops /mnt/tlv-s-comp-prod/drops

ls /mnt/tlv-s-comp-prod/drops/

echo "cleanup workspace"
rm ${WORKSPACE}/*.txt &> /dev/null

i="0"
while [ $i -lt 6 ]
do

  if [[ ${BASE_PATH} == *"Baseline"* ]]; then
      unset BRANCHES[@]
      declare -A BRANCHES
      BRANCHES[Baseline]=
  fi
  for BRANCH in "${!BRANCHES[@]}"; do
      echo "BRANCH: $BRANCH"
      if [ $BRANCH == "Baseline" ]; then BRANCH=; fi
      img_dir=$(ls -td -- ${BASE_PATH}/${BRANCH}/*/ | head -n 1)
      echo "img_dir: $img_dir"
      IMG_PATH=$(ls $img_dir*.rpm)
      echo "IMG_PATH: $IMG_PATH"
      cd $img_dir
      IMG_NAME=$(ls *.rpm) > env.properties
      if [ ! -z "$IMG_NAME" ]; then
          if [ $(( $(date +%s) - $(stat -c %Z $IMG_PATH) )) -lt 10000800 ]; then
            echo "IMG_NAME: ${IMG_NAME}" 
            #BRANCHES[$BRANCH]=$IMG_PATH
            #echo "REG_OSA_SOFTSYNC_BUILD_IMG_FULL_PATH=${BRANCHES[$BRANCH]}" >> ${WORKSPACE}/$BRANCH.txt
            echo "BRANCH_NAME=$BRANCH" >> ${WORKSPACE}/${BRANCH}_branch.txt
            echo "REG_OSA_SOFTSYNC_BUILD_NAME=$BRANCH-$IMG_NAME" >> ${WORKSPACE}/${BRANCH}_branch.txt
           
          else
              echo "$IMG_NAME is out dated"
          fi  
      else
          echo "IMG_NAME is empty"
      fi
            BRANCH_NAME=""
  done
  
  $TEMP=$BRANCH_NAME
  echo "TEMP: $TEMP"
  

  if [ $(ls ${WORKSPACE}/*_branch.txt | wc -l) == $(echo ${#BRANCHES[@]}) ]; then break; fi
  
  #for i in $(ls *_branch.txt); do i=$(echo $i | awk -F '_branch.txt' '{print $1}'); if [ $(echo ${!BRANCHES[@]} | grep $i | wc -l) == 0 ]; then state=1 break; fi done
  
  
  i=$[$i+1]
  
  sleep 1800
  
done

This is the "Trigger parameterized build on other projects" configuration:

0 Answers
Related