bashjenkinseofjenkins-pipeline-unit

EOF: command not found in Jenkins Pipeline


I'm trying to launch Datadog agent in Jenkins pipeline, but I'm getting below errors:

line 7: warning: here-document at line 2 delimited by end-of-file (wanted `EOF'). EOF: Command not found Error.

    stage('Install Datadog agent'){
        when {
            environment(name: "DATADOG_REQ", value: "enable")
            }
        steps {
            script {
            echo "Installing Datadog Agent"
            
            sh '''#!/bin/bash 
                ssh -o ConnectTimeout=30 -t  ABC@1234 /bin/bash  << EOF || error_exit "creating based folder failed for $service_name"
                sudo chmod u+x ./${JOB_NAME}/enableDatadogAgent.sh
                sudo chown jenkins:jenkins ./${JOB_NAME}/enableDatadogAgent.sh
                echo ${DATADOG_REQ} ${JOB_NAME}
                ./${JOB_NAME}/enableDatadogAgent.sh ${DATADOG_REQ} 
                EOF'''
                }



            }
        }

Any help would be very helpful.


Solution

  • I changed the << EOF with <<- _EOF_, and now it's working.

                script {
                echo "Installing Datadog Agent"
                
                sh '''#!/bin/bash 
                    ssh -o ConnectTimeout=30 -t  ABC@1234 /bin/bash  <<- _EOF_ || error_exit "Failed to execute while doing SSH"    
                        sudo chmod u+x ./${JOB_NAME}/enableDatadogAgent.sh
                        sudo chown jenkins:jenkins ./${JOB_NAME}/enableDatadogAgent.sh
                        echo ${DATADOG_REQ} ${JOB_NAME}
                        ./${JOB_NAME}/enableDatadogAgent.sh ${DATADOG_REQ} 
                        _EOF_'''
    
                    }