首页 > 解决方案 > 字符串被转义,如何安全打印

问题描述

我遇到的问题是以下字符串转义和错误,例如:

Dont' did not match any file(s) known to git
error: pathspec 'display' did not match any file(s) known to git
error: pathspec 'Recipes' did not match any file(s) known to git
error: pathspec 'if' did not match any file(s) known to git
error: pathspec 'active' did not match any file(s) known to git
error: pathspec 'subscription' did not match any file(s) known to git
error: pathspec 'is' did not match any file(s) known to git
error: pathspec 'missing' did not match any file(s) known to git

代码:

  gitlogFirst = sh(returnStdout: true, script: 'git log -n1 --pretty=\'format:%s\'').trim()
  gitlogRest = sh(returnStdout: true, script: 'git log --pretty=\'format:%s\' ${GIT_PREVIOUS_SUCCESSFUL_COMMIT:-HEAD^}..HEAD^').trim()
  gitMsg = "${cimsg}\n\n${gitlogFirst}\n${gitlogRest}"
  authorName = 'Jenkins CI'
  authorEmail = 'ci@jenkins'
  author = "${authorName} <${authorEmail}>"
  dir (path) {
    sh "git add . && GIT_COMMITTER_NAME='${authorName}' GIT_COMMITTER_EMAIL='${authorEmail}' git commit --author='${author}' -m '${gitMsg}' || :"
    withCredentials([usernameColonPassword(credentialsId: '***', variable: 'GIT_CRED')]) {
      sh "git push https://${GIT_CRED}@github.com/xxx/xxxx.git ${branch}"
    }
  }

如何安全地为变量转义 java/groovy 中的字符?

标签: javagroovy

解决方案


尝试制作

获取

您的本地存储库从 github 获取所有新信息。它只需要有关新分支的信息,而不需要真正的代码。在那之后,

git结帐

应该可以正常工作。


推荐阅读