If condition does not work in gradle task


(sakshi) #1

I have a task to clone a repo like this :

class CloneComponentDistributionTask extends DefaultTask {
@TaskAction
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)

System.setProperty('org.ajoberstar.grgit.auth.username',uname)
System.setProperty('org.ajoberstar.grgit.auth.password',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.


(Chris Doré) #2

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


(sakshi) #3

Yes, buildNumber is bNo.