jenkins pipeline 报 unexpected char: '\' 错误
Serveices Jenkins 734

问题:

在写jenkins pipeline script的时候,如果字符里面有\字符,比如这样:

pipeline {
  agent any

  stages {
    stage('Check virtualenv') {
      steps {
          sh """
            rm -r /mnt/x/some/directory/Problem\ 1.0/path
          """
      }
    }
  }
}

会提示一个错误:WorkflowScript: 4: unexpected char: '\'

解决方法:

\ 字符是 Groovy 中的一个特殊字符。如果需要这个\字符,可以这样写:

pipeline {
  agent any

  stages {
    stage('Check virtualenv') {
      steps {
          sh """
            rm -r /mnt/x/some/directory/Problem\\ 1.0/path
          """
      }
    }
  }
}
jenkins pipeline 报 unexpected char: '\' 错误
https://www.seafog.cn//archives/355235425
作者
seafog
发布于
更新于
许可协议