如何修复 sed 命令以使其在 groovy 中工作

如何修复 sed 命令以使其在 groovy 中工作

我有以下可以在 gitlab 中运行的代码(没有该sh部分):

sh '''
mkdir ./pylint
docker run --rm --entrypoint=/usr/local/bin/pylint ${IMAGE_NAME}:${IMAGE_VERSION} --rcfile=.pylintrc --exit-zero ${MODULE} > ./pylint/pylint.log
PYLINT_SCORE=$(sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p' ./pylint/pylint.log)
'''

它的作用是8.52从这个输出中获取值:Your code has been rated at 8.52/10

我也试图在中使用它Jenkinsfile,但出现以下异常:

WorkflowScript: 50: unexpected char: '\' @ line 50, column 75.
   /^Your code has been rated at \([-0-9.]*

知道如何修复它吗?或者使用其他命令来sed获取所需的输出?

答案1

正确的命令是:

PYLINT_SCORE=$(sed -n 's#^Your code has been rated at \\([-0-9.]*\\)/.*#\\1#p' ./pylint/pylint.log)

相关内容