Execute command which has "$" with commandLine

When I execute manually the below command through command line everything works fine.

docker stop $(docker ps -q --filter name=zalenium)

I tried to add it in a gradle exec task like this:

task zaleniumStop(type: Exec) {
commandLine ‘docker’, ‘stop’, ‘$(docker ps -q --filter name=zalenium)’
}

But it fails because it doesn’t recognise that it should execute the part after ‘$’ and see it as string:

“Error response from daemon: No such container: $(docker ps -q --filter name=zalenium)”

I have also changed it like the below with no success.

commandLine ‘docker’, ‘stop’, ‘$(docker ps -q --filter name=zalenium)’

I have tried the below and seem to work:

task zaleniumStop() {
def cmd = ‘docker stop $(docker ps -q --filter name=zalenium)’
["/bin/bash", “-c”, cmd].execute()
}

Is there a way to make this work with commandLine?