Jenkinsfile Unterminated quoted string

Viewed 2927

My Jenkinsfile build fails with Syntax error: Unterminated quoted string

This stage which fails:

stage('Clean Volume') {
    steps {
        sh '''
            docker images --format="{{.Repository}} {{.Tag}} {{.ID}}" |
                grep -v "latest" |
                cut -d ' ' -f3 |
                xargs docker rmi -f"
            '''         
     }
}

What is the problem with syntax here?

2 Answers

With all the upsides of the triple single-quote string, there is a natural consequence of needing to escape single quotes and backslashes that are part of our string.

def specialCharacters = '''hello \'John\'. This is backslash - \\ \nSecond line starts here'''

The line

xargs docker rmi -f"

ends with a starting " symbol that is never closed.

Related