Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Trigger the build task by tag #72

CaoFangyuan ·

Hi,

I wonder can we trigger the build task by detecting is there a new tag in the repo, if yes, then get the code of this tag to do the build? Thanks.

  • replies 13
  • views 1379
  • stars 0
robinshen ADMIN ·

Which SCM are you using?

CaoFangyuan ·

I am using bitbucket and the repository setting type is git. I saw that it has one setting my related to this, but seems the tag name here is fixed, could we use the regular expression?

Capture.PNG
steveluo ADMIN ·
CaoFangyuan ·

Hi@steveluo ,
Sorry for the slow response, one question is actually for repository setting I am not using Bitbucket Server I am using Git instead, because when I use Bitbucket Server, I will get below error message while the Git setting works. Does the method you replied upper can work with Git configuration also?
Capture.PNG

admin ·

Hi@CaoFangyuan,

What I aforementioned can only works with BitBucket Server or BitBucket cloud.

The error occurred is caused by SSL issue. Do you use SSL for your bitbucket server? If you can also use http (not https) to access the bitbucket server, you may try fill in the field RESTful API Url like below:

Pasted_Image_2022_7_19__22_45.png
CaoFangyuan ·

Hi@admin,

Yes, my bibbucket server is using SSL, previous we use https in RESTful API Url it works well, and it shows this error when we upgrade the quick build to 10.0.39, so I changed to git then.

steveluo ADMIN ·
CaoFangyuan ·

@steveluo

This is owned by another team of my company, let me check with them. So the thing is if I use git configuration as my repository setting, then is there any method can achieve this tag trigger? Is the webhook the only way to do this?

steveluo ADMIN ·

Hi@CaoFangyuan

Just noticed that the issue should have been fixed in QB 11.0.7. Please either upgrade your QuickBuild to 11.0.7 or later or don't use self-signed certificates in your BitBucket server.

Yes, the recommended/only way is to use webhook if you want to trigger build when tag is created.

CaoFangyuan ·

@steveluo
Ok, Thanks. With web hooker, it will trigger the quick build when there is a new tag? Can I use regular expression to only trigger the quick build if the the tag name matches specific pattern?

steveluo ADMIN ·

Hi@CaoFangyuan ,

With web hooker, it will trigger the quick build when there is a new tag?

Yes. That is the only way if you want to trigger a build whenever the tag is created.

Can I use regular expression to only trigger the quick build if the the tag name matches specific pattern?

Yes. You can use groovy script for field Trigger Condition. For example, below is to tell QuickBuild only trigger build when tag with prefix REL- is created:

if (!(delivery.changes.size() > 0 && delivery.changes.get(0).ref.type == "TAG")) 
  return false; 

String tag = delivery.changes.get(0).refId.substring("refs/tags/".length()); 
return tag.startsWith("REL-");```
CaoFangyuan ·

Hi@steveluo ,

I tried from myside, the webhook sometimes works well, but sometimes it doesn't work, it seems it triggered but not satisfied with the build condition. I do have one question about the trigger condition in webhook and build condition in general setting, what's the difference between these two? I also tried to get the tag name in build name with script, but seems get the below error, here is my setting:
error.PNG
general.PNG
webhook.PNG
Another thing is can we achieve that to detect the tag creation of multiple repositories? Once new tag is detected in any one of these repositories, then trigger the quick build.

steveluo ADMIN ·

Hi@CaoFangyuan ,

I just wanna do you use the script I posted before? Do you use the webhook to trigger the build?

If you want to trigger the build only when your tag contains burn, you may just replace REL- with burn like below in your webhook Trigger Condition field:

if (!(delivery.changes.size() > 0 && delivery.changes.get(0).ref.type == "TAG")) 
  return false; 

String tag = delivery.changes.get(0).refId.substring("refs/tags/".length()); 
return tag.contains("burn");

The Build Condition field is for all builds triggered, not matter it is triggered manually, periodically, or by webhook, while what aforementioned script in webhook Trigger Condition is only for webhook received.

The error in your post means that sometimes the tag variable is populated and sometimes not. If you only want to trigger the build when tag is created, you needn't set build condition here. Otherwise, you needn't set webhook Trigger Condition field, instead, you can just pass the tag from webhook to the variable as what I have mentioned in comment #4.