linuxfindgitlabrunnerbasename

Trouble using Find and Prune Command to filter out file name in GitLab runner


So, this is strange and I'm not sure what is causing it.. (I'm very new to cli stuff)

I have a directory ==> SomeDirectory I have two jar files ==> original-processor.jar and processor.jar I am looking to just return processor.jar and set it as a variable, basically anytime there is an original-* I want to ignore it.

I do the following within EC2 (amazon linux) and it works

JAR_FILE_NAME=$(basename $( find . -maxdepth 1 -type f -name '*original*.jar' -prune -o -name '*.jar' -print))

Output ==> processor.jar

But when i run this exact same command in GitLab's cicd pipeline:

Output ==> original-processor.jar

Does anyone know what the discrepancy could be? Is this the best way to accomplish what I want?

I appreciate any input.


Solution

  • -prune is only meaningful for directories, it prevents descending into it. It has no effect when the element is a file.

    If you want to exclude something from the results, use -not before the criteria.

    find . -maxdepth 1 -type f -name '*.jar' -not -name '*original*.jar'
    

    If you're using bash, you can enable extended globbing and use the negative matching operator.

    shopt -s extglob
    JAR_FILE_NAME=$(echo !(*original*).jar)