-2
#!/bin/bash 

*********************************************************
#The script will create Jenkins Instance"
*********************************************************
set -e

if [ $# -lt 4 ]; then
    echo "Usage: ./JenkinsInstance.sh <InstanceName> <Constraint-node> <Jenkins_version> <Volume>"
    echo "Usage: ./JenkinsInstance.sh <php> <apsrp10669> <Jenkins:2.150.2> <jenkins_data4>"
    exit 0
fi

Instance_Path=~/Downloads/vinu-WorkStuff/ShellScripts/jenkins_masters
#utils_path=~/Downloads/vinu-WorkStuff/ShellScripts/utils

export Instance_Name=$1
export ConstraintNode=$2
export Jenkins_version=$3
export Volume=$4

echo $Instance_Name 
echo $ConstraintNode 
echo $Instance_Path
echo $Volume
echo $Jenkins_version

***************************************
#Checking the Disk space of the $Volume
**************************************
sh $Instance_Path/../DiskSpace
sh $Instance_Path/../env

**************************************
#Setting up the env variables
*************************************
cd $Instance_Path

if [ -d $Instance_Path ]; then
    echo "$Instance_Path exists and proceed with pulling the git update from the master branch"
    cd $Instance_Path/production
    git pull origin master
  else
    echo "$Instance_Path doesn't exists in the path"
fi

*************************************
#define the docker-compose template
*************************************
cd $Instance_Path/production

if grep -q "$Instance_Name" docker-compose.yml;
 then
   echo "$Instance_Name is found in the docker file"
   exit 0
else
   echo "$Instance name is not found and proceed with pushing the docker template"

    if [ -f $Instance_Path/production/docker-compose.yml ]; then

    echo "docker-compose.yml file exists" 

    cat <<-EOT >> $Instance_Path/production/docker-compose.yml

     $Instance_Path:
            image: docker.vinu.com/vinu/jenkins:2.150.2
                extends:
           file: common-services.yml
           service: jenkins_master
                labels:
               com.docker.ucp.access.label: "$1"
            environment:
                   JENKINS_OPTS: --prefix=/$1
           constraint:node: "=$ConstraintNode.uhc.com"
                volumes:
            - /$Volume/instances/$Instance_Name/jenkins_home:/var/jenkins_home  
        EOT
  else
    echo "Docker-Compose.yml file doesn't exists in the proudction directory"
  fi
fi

**************************************************
echo "Instance creation by invoking instance script"
**************************************************

cd $Instance_Path/../utils/bin/instance_creation/

 if [ -f createNewInstance.sh ]; then
  echo Script exists and procee with Instance up.
  echo Pull the latest updates from master branch
  git reset --hard
  git pull origin master 

  sh ./createNewInstance.sh $Instance_Name
else
  echo Script not found under utils path
 fi

cd $Instance_Path

if [[ ! -f $Instance_Path/bin/dc-up.sh ]] && [[ ! -f $Instance_Path/bin/reload-proxies.sh ]]; then
   echo "Required files are present"
   ls -l
   ../bin/dc-up.sh $Instance_Name
   ../bin/reload-proxies.sh 
else
  echo "Files are not present under $Instance_Path/bin path"
  exit 0;
fi

*****************************************************
echo Checking the instance is up and running or not
***************************************************** 
  docker ps -a | grep $Instance_Name

*************************************************
echo "Jenkins Instance created successfully"
*************************************************

Output with errors :

/JenkinsInstance.sh php dsds asds as
./JenkinsInstance.sh: line 3: DiskSpace.sh: command not found
./JenkinsInstance.sh: line 5: DiskSpace.sh: command not found
php
dsds
/c/Users/kvinod5/Downloads/vinu-WorkStuff/ShellScripts/jenkins_masters
as
asds
./JenkinsInstance.sh: line 28: DiskSpace.sh: command not found
./JenkinsInstance.sh: line 30: DiskSpace.sh: command not found
sh: /c/Users/kvinod5/Downloads/vinu-WorkStuff/ShellScripts/jenkins_masters/../DiskSpace: No such file or directory
sh: /c/Users/kvinod5/Downloads/vinu-WorkStuff/ShellScripts/jenkins_masters/../env: No such file or directory
./JenkinsInstance.sh: line 34: DiskSpace.sh: command not found
./JenkinsInstance.sh: line 36: DiskSpace.sh: command not found
/c/Users/kvinod5/Downloads/vinu-WorkStuff/ShellScripts/jenkins_masters exists and proceed with pulling the git update from the master branch
remote: Enumerating objects: 15, done.
remote: Counting objects: 100% (15/15), done.
remote: Total 28 (delta 15), reused 15 (delta 15), pack-reused 13
Unpacking objects: 100% (28/28), done.
From https://github.vinu.com/jenkins/jenkins_masters
 * branch            master     -> FETCH_HEAD
   a1ebb66..ae10b0b  master     -> origin/master
Updating a1ebb66..ae10b0b
Fast-forward
 production/docker-compose.yml | 43 +++++++++++++------------------------------
 1 file changed, 13 insertions(+), 30 deletions(-)
./JenkinsInstance.sh: line 47: common-proxy.yml: command not found
./JenkinsInstance.sh: line 49: common-proxy.yml: command not found
./JenkinsInstance.sh: line 120: warning: here-document at line 63 delimited by end-of-file (wanted `EOT')
./JenkinsInstance.sh: line 121: syntax error: unexpected end of file

closed as off-topic by mdpc, Kusalananda Apr 2 at 6:41

  • This question does not appear to be about Unix or Linux within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Can you please give me the right solution for the script to avoid errors @kus – Kandikuppa Vinod Apr 1 at 14:05
  • 1
    You have multiple lines saying ***** without a comment character (#) in front of it. This will cause the script to execute the files in the current directory. Do consider making these lines proper comments. – Kusalananda Apr 1 at 14:11
  • 1
    most of the error suggests that the issue is with ./JenkinsInstance.sh script. can u share that? – msp9011 Apr 1 at 14:13
  • I shared the entire script in the above question. I just give the exit condition if the parameters are not met. – Kandikuppa Vinod Apr 1 at 14:19
  • 1
    Just make the ****-line proper comments. Without a leading # on those lines, it would try to execute the first thing in the directory as a command with everything else as arguments. – Kusalananda Apr 1 at 14:27
1

Try this,

if [ -f $Instance_Path/production/docker-compose.yml ]; then

echo "docker-compose.yml file exists" 

cat <<-EOT >> $Instance_Path/production/docker-compose.yml

 $Instance_Path:
        image: docker.optum.com/optum/jenkins:2.150.2
            extends:
       file: common-services.yml
       service: jenkins_master
            labels:
           com.docker.ucp.access.label: "$1"
        environment:
               JENKINS_OPTS: --prefix=/$1
       constraint:node: "=$ConstraintNode.uhc.com"
            volumes:
        - /$Volume/instances/$Instance_Name/jenkins_home:/var/jenkins_home  
EOT
else
    echo "Docker-Compose.yml file doesn't exists in the proudction directory"
fi
  • By the syntax of heredoc, there shouldn't be any characters other than delimiter EOT to close heredoc. But in the script delimiter EOT is prefixed with spaces/tab.
  • There is an unnecessary if at the end of the script
  • 1
    Ok i understood that fi is unncessary and i will show my complete script and correct what am doing wrong... – Kandikuppa Vinod Apr 1 at 13:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.