EOF:在Jenkins Pipeline中未找到命令

ia2d9nvy  于 2023-05-16  发布在  Jenkins
关注(0)|答案(2)|浏览(184)

我尝试在Jenkins管道中启动Datadog代理,但出现以下错误:

第7行:警告:here-document位于第2行,由文件结尾分隔(需要“EOF ')。EOF:命令未找到错误。

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


            }
        }

任何帮助都会很有帮助。

gkn4icbw

gkn4icbw1#

我用<<- _EOF_改变了<< EOF,现在它可以工作了。

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

                }
uurity8g

uurity8g2#

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

}这个工作尝试像这样的代码<< EOF你的命令<< EOF

相关问题