Treat tags the same as branches


#1

When I create a new branch in git-hub circle-ci magically notices and builds it. It would be great if it did exactly this for tags as well.

Essentially, my build generates various artefacts which I haven’t figured out how to push back to git-hub yet. If builds were also trigged by tags then my problem would be solved as users who need the artefacts could simply click on the appropriate tag.

I can get exactly what I want now by using branches instead of tags, but that is irksome :slight_smile:


#2

We actually do trigger for tags as described here. The difference is that tags do not trigger builds by default, and the build will only be run if there is a deployment section that matches the tag that has been created / pushed.


#3

Thanks Alexey. I don’t want to deploy anything though - is the following fragment sufficient:

  release:
    tag: /release-.*/
    owner: circleci```

or must I do:

```deployment:
  release:
    tag: /release-.*/
    owner: circleci
  commands:
    - ./do-nothing.sh```

#4

The behaviour with an empty commands section is undefined, so you’ll have to specify at least something to run there. But a simple true would suffice:

deployment:
  release:
    tag: /release-.*/
    owner: circleci
    commands:
      - "true"

EDIT: added quotes around the true command, as otherwise YAML interprets that as a boolean while CircleCI expects a command. Thanks @yatesco for pointing it out.


#5

Thanks Alexy.


#6

Actually, this isn’t working. At least, with the following circle.yml pushing a tag does nothing:

machine:
  java:
    version: oraclejdk8

 ## Customize dependencies
dependencies:
  cache_directories:
    - "~/.m2"

test:
  override:
    - lein full-build!
  post:
    - mkdir -p $CIRCLE_TEST_REPORTS/junit/
    - find . -type f -regex ".*/target/test-reports/.*xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \;

general:
  artifacts:
    - "target/*.war"

deployment:
  release:
    tag: /v[0-9]+(\.[0-9]+)*/
    owner: circleci
    commands:
      - (true)

(NOTE: I had to use (true) rather than true otherwise the build failed)


#7

Could you please give us the name of the tag that you pushed? I’d like to try to reproduce it in my sample project.


#8

Hi Alexey - I replied to your email with the private links - would you prefer a public repo demoing the behaviour?


#9

Sorry, I don’t think I have received the links. Would it be possible to replicate the behaviour with a public project? Thank you very much for your effort.


#10

Hi Alexey, I just received a bounced email :-).

The tag was v1.0.2 and v1.0.3 but I will try and reproduce in a public project when I get time (probably not for the next week or two)


#11

Thanks @yatesco, will be waiting for your follow-up.


#12

The tag regexp based deployment is not working for me. I was ssh-ing into the build machine, and realized, that the checkout step doesn’t pulls the tags …

I’m not sure about the implementation details about the checkout. Is it shell-ing to: git checkout, or its using the github api directly?

Anyway, my workaround was to add a pre step, to fetch the tags:
dependencies: pre: - git fetch --tags


#13

Thanks lalyos, so does pushing a tag cause a new ci-build and does that tag appear in the list on circle-ci?


#14

adding - git fetch --tags is not working as well. tags are not triggering a new build


#15

after all got it to work. it doesn’t show the build under the branch the tag was made on and you can’t define branch and tag for the same deployment. which is what I actually need.


#16

@alexey I’ve followed the documentation to trigger a build only on a matching tag, buy first whitelisting the branch name to a fake name that never exists (so that no regular commits to any branch will trigger a build). Then I added the tag option under deploy with a regex that matches the tag name. According to docs, the tag will trigger a build because it matches the tag. But in reality, a matching tag ‘v1.0.0’ simply gets marked as ‘not run’.

general:
  branches:
    only:
      - nonExistantBranch
deployment:
  release:
    tag: /v[0-9]+(\.[0-9]+)*/
    commands:
      - do some stuff

#17

Sorry for the delay here.

I assume that it has to do with the branch ignore mechanism. I will file a bug on this, in the meanwhile we’ll have to look for a different solution.

One question: per your development workflow, do you always tag contents of different branches? Or the code that gets deployed is always on the master branch? If it is on master, you could probably only ignore the master branch—and this should work around the issue.


#18

This should be fixed now. Could you please try running builds like that again?


#19

Hi Alexey, tagged bulids still don’t seem to work. Even just using the example on the config page still no build is triggered.


#20

You are referring to this example in the docs, is that right? I cannot reproduce the issue locally—would you mind posting all the sections of your current circle.yml here, except for machine, dependencies, and test? Thanks.