'Escape & character in groovy script while using curl

I'm using bash execution of curl in groovy script:

   descr = """
    curl --silent -k -u test:test "https://bitbucket/rest/api/1.0/projects/test/repos/test/pull-requests?state=all&at=refs/heads/release/test" | /usr/bin/core_perl/json_pp
    """
    def descrtxt = ['bash', '-c', descr].execute()
    descrtxt.waitFor()

Problem is curl ignoring & symbol in request.And instead of give me only request with test refs,give me all pr. I try to escape it with '&' and \& but no luck



Solution 1:[1]

use ''' for the bash command and double in the curl command

descr = '''
    curl --silent -k -u test:test "https://bitbucket/rest/api/1.0/projects/test/repos/test/pull-requests?state=all&at=refs/heads/release/test" | /usr/bin/core_perl/json_pp
    '''
    def descrtxt = ['bash', '-c', descr].execute()
    descrtxt.waitFor()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 BalRog