简体   繁体   中英

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

So I have a simple script running in an IF statement. I always get: syntax error: unexpected end of file (expecting "fi") I am wondering what could be the possible solution for this?

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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