0

I have the following code which works in gitlab (without the sh part):

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)
'''

what it does, it takes the value 8.52 from this output: Your code has been rated at 8.52/10

I'm trying also to use it in Jenkinsfile, but gets the following exception:

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

any idea how to fix it? or use other command from sed to get the require output?

2
  • I don't know if this is a sed error, but you could try with sed -r option (extended regex) and another separator in s/// command: sed -nr 's@^Your code has been rated at ([-0-9.]*)/.*@\1@p'
    – Paulo
    Nov 25, 2020 at 4:57
  • I got: PYLINT_SCORE=$'\001'
    – arielma
    Nov 25, 2020 at 16:24

1 Answer 1

0

The correct command is:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .