java - 字符串被转义,如何安全打印
问题描述
我遇到的问题是以下字符串转义和错误,例如:
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 中的字符?
解决方案
尝试制作
获取
您的本地存储库从 github 获取所有新信息。它只需要有关新分支的信息,而不需要真正的代码。在那之后,
git结帐
应该可以正常工作。
推荐阅读
- azure-application-insights - 应用程序洞察无法下载 nuget 包
- jdbc - 使用 tableau 的 JDBC 连接是否需要用户名和密码?
- mysql - 如何在 vb.net 中按数据视图分组
- java - 如何在java中按对象值对JsonNode进行排序
- reactjs - 使用 react-chartjs-2 增加图例和图表之间的填充
- python - Pycharm 在不同的控制台中运行
- python - 如何将熊猫列表行转换为 numpy 数组?
- react-native-flatlist - 将数据添加到响应本机 Web 上的 FlatList,同时保持可见内容
- react-hooks - 验证后 React Hook useCallback()?
- javascript - 关闭浏览器的查找 (CTRL + F)