If condition does not work in gradle task

I have a task to clone a repo like this :

class CloneComponentDistributionTask extends DefaultTask {
def cloneComponent(){

def uname = System.getenv('bamboo_uname')
if (!uname ) {
    throw new Exception('bamboo_uname  is not set')

def password = System.getenv('bamboo_password')
if (!password) {
    throw new Exception('bamboo_password is not set')

def credentials = new org.ajoberstar.grgit.Credentials(uname, password)

def bNo = System.getenv('bamboo_bNo')
if (bNo) {
    def grgit = org.ajoberstar.grgit.Grgit.clone(dir: "${repoLocation}", uri: gitRepo)



I want to clone the repo if bNo is present or else it should not clone. But the fact is that the if condition does not work at all. That means even if bNo has a value, this condition would still not work. Any ideas to mke this task clone the repo if bNo has a value.

Is ‘buildNumber’ in the if supposed to be ‘bNo’?

Yes, buildNumber is bNo.