简体   繁体   English

语法错误:文件意外结束(预期“fi”)

[英]syntax error: unexpected end of file (expecting "fi")

So I have a simple script running in an IF statement.所以我有一个在 IF 语句中运行的简单脚本。 I always get: syntax error: unexpected end of file (expecting "fi") I am wondering what could be the possible solution for this?我总是得到:语法错误:文件意外结束(期待“fi”)我想知道可能的解决方案是什么?

def call(Map config) {
    withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'JENKINS_AWS'],
      sshUserPrivateKey(credentialsId: 'JENKINS-SSH', keyFileVariable: 'SSH_KEY')]) {
        sh """
            #!/bin/bash
            source add_ssh_key "${SSH_KEY}"           
            source init_env "${TARGET_STAGE}"
            source create-bastion-pod "${PROMETHEUS_PUSHGATEWAY}" "${PROMETHEUS_PUSHGATEWAY_PORT}"  
            if [ ${TARGET_STAGE} == 'dev' ]; then
               cat <<-EOF | curl --data-binary @- \${BASTION_URL}/metrics/job/sone_job 
            # TYPE some_metric counter
            some_metric{label="val1"} 42 
            EOF
            fi
            delete-bastion-pod
        """
    }
}

<<- only strips tabs from the here-document; <<-仅从此处文档中删除选项卡 your closing delimiter appears to be indented (according to what Groovy actually presents to the shell) with a couple of spaces.您的结束分隔符似乎缩进(根据 Groovy 实际呈现给外壳的内容)带有几个空格。 Try something like尝试类似的东西

    sh """
        #!/bin/bash
        if [ ${TARGET_STAGE} == 'dev' ]; then
           cat <<EOF | curl --data-binary @- \${BASTION_URL}/metrics/job/some_job 
        # TYPE some_metric counter
        some_metric{label="val1"} 42 
        EOF
        fi
    """

Note that as far as the shell executing the script is concerned, the here-document and the closing EOF aren't indented at all.请注意,就执行脚本的 shell 而言,此处的文档和结束的EOF根本没有缩进。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM