0

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.

Deepakvg
  • 71
  • 2
  • 9
  • I'm not familiar with Jenkins syntax, but are the spaces the script is indented with removed before it's executed? If not, that'll cause this error, because the here-document delimiter (`EOF` in this case) is not recognized if it's indented (unless you use `<<- EOF` *and* indent only with tabs; see [this question](https://stackoverflow.com/questions/21681843/shell-script-about-cat-eof)). – Gordon Davisson Feb 04 '22 at 18:14

2 Answers2

0

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_'''

                }
Deepakvg
  • 71
  • 2
  • 9
0
  stage('Deploy to server') {
        steps {
            sshagent(['SSH_CREDENTIALS']) {
                sh '''
                
                    ssh -i ${PEM_KEY_PATH} ubuntu@65.2.169.55 << EOF
                        set +x
                        export DOCKER_USERNAME=\$(docker-credential-jenkins get ${DOCKER_REGISTRY} | jq -r '.Username')
                        export DOCKER_PASSWORD=\$(docker-credential-jenkins get ${DOCKER_REGISTRY} | jq -r '.Secret')
                        docker login -u \$DOCKER_USERNAME -p \$DOCKER_PASSWORD
                        docker pull ${DOCKER_REGISTRY}/${IMAGE_NAME}:latest
                        docker run -d -p 3000:3000 ${DOCKER_REGISTRY}/${IMAGE_NAME}:latest
                    << EOF
                '''
            }
        }
    }
}

} this working try like this code << EOF your commands << EOF