Mariusz Jaskółka
Mariusz Jaskółka

Reputation: 4482

Jenkins use expression/parenthesis in shell command

How to make file expressions work with Jenkinsfile? I want to run simple command rm -rv !(_deps) to remove all populated files except _deps directory. What I've tried so far:

Upvotes: 1

Views: 689

Answers (1)

ycr
ycr

Reputation: 14574

In Bash to use pattern matching you have to enable extglob:

So the following will work. Make sure your shell executor is set to bash.

sh """
   shopt -s extglob
   rm -rv !(_deps)
  """

If you don't want to enable extglob you can use a different command to get the directories deleted. Following is one option.

ls | grep -v _deps | xargs rm -rv

In Jenkins

 sh """
    ls | grep -v _deps | xargs rm -rv
    """

Upvotes: 1

Related Questions