3

The below is my Jenkins Pipeline stage

stage ('Import') {

            steps {
                sshagent([sshCredentials]) {
                    sh '''
                        #!/bin/bash
                        sh -x ETL_AUTOMATION/Scripts/export.sh
                    '''

Build Output:-

[[ RMO_TST12 ==  ]]

ETL_AUTOMATION/Scripts/export.sh: 17: ETL_AUTOMATION/Scripts/export.sh: [[: not found

IF Condition in Script:-

if [[ "$SOURCE_FOLDER" == "" ]]; then

    echo "SOURCE_FOLDER not specified... exiting"
    exit 1
fi

I have mentioned #!/bin/bash in my script also.

Please help me, I am really struck here.

9

You are running sh -x ETL_AUTOMATION/Scripts/export.sh. This means that export.sh is being run by sh and not bash. On Ubuntu, sh is a simple POSIX shell called dash and that doesn't support the [[ construct, which is a bash thing. So just change your script so that it is launched with bash instead of sh. I don't know the Jenkins syntax at all, but I suspect you want one of these:

sshagent([sshCredentials]) {
    sh '''
        ETL_AUTOMATION/Scripts/export.sh
        '''

or, if your export.sh isn't executable:

sshagent([sshCredentials]) {
    sh '''
        bash ETL_AUTOMATION/Scripts/export.sh
        '''

Or, perhaps simply:

sshagent([sshCredentials]) {
    bash '''
        ETL_AUTOMATION/Scripts/export.sh
        '''

Alternatively, you can change export.sh so it doesn't use bash-only features:

if [ -z $SOURCE_FOLDER ]; then
    echo "SOURCE_FOLDER not specified... exiting"
    exit 1
fi
  • thank you man this worked :) – yeswanth Dec 9 '19 at 6:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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