6

I have an AWS Pipeline that is connected to GitHub via CodeStar Connection. The process looks like this:

  1. Pull source from GitHub
  2. Build project
  3. Run tests
  4. Deploy

Before (or as part of) step 4 I would like the AWS Pipeline to tag the code with a git tag and then push this back to the repo in GitHub.

How can I do this?

prosoitos
  • 6,679
  • 5
  • 27
  • 41
Milk
  • 2,469
  • 5
  • 31
  • 54
  • I don't know anything about AWS pipeline, but to push tags to a remote (e.g. GitHub) with Git, you need to use either the `--tags` flag to push all the tags at once (e.g. `git push origin --tags`) or `git push origin ` to push a single tag. By default, Git does not push tags to remotes. See "Sharing tags" in [the tag chapter of Git book](https://git-scm.com/book/en/v2/Git-Basics-Tagging) for more info. That said, I don't know whether this helps you in your context. – prosoitos Oct 11 '20 at 22:25
  • @milk Did you figure it out? – systemdebt Oct 15 '21 at 18:08
  • I am trying to do the same thing and I was able to solve one part of the problem, that is to get the .git folder as part of the clone. For this, you need to select code_build_clone_output=True in your source action. This allows codebuild to clone the repository. But, I am not able to use the same connection to push the tag. – ajain Dec 05 '22 at 07:26

1 Answers1

-1

You will need a CodeBuild action before/after Step4 in the Pipeline that will basically execute the git tagging commands and push to origin as mentioned by other commenters. A sample buildspec for CodeBuild project will look like:

version: 0.2 

env:
  git-credential-helper: yes


phases: 
  install: 
    runtime-versions: 
      python: 3.7 

  build: 
    commands: 
      - echo Build started on `date`
      - git checkout master
      - git tag ${BUILD_NUMBER} ${CODEBUILD_RESOLVED_SOURCE_VERSION}
      - git push origin master --tags ${BUILD_NUMBER}
shariqmaws
  • 8,152
  • 1
  • 16
  • 35
  • 3
    This doesn't work. git tag applies the tag to the local repository, but codebuild doesn't give you a repository - only a zip file of the given commit. – Bill Shubert Sep 01 '21 at 17:06
  • @BillShubert what about getting a full clone? – systemdebt Dec 23 '22 at 02:15
  • Yes, checking out a full clone from within codebuild would work, but it is very slow. I was hoping there was some way to push a tag directly to a remote repository, but I guess not. In the end I created an SQS that has tagging requests, then on a computer that always has the code checked out it monitors that queue. Pretty ugly but I couldn't find anything better. – Bill Shubert Jan 06 '23 at 21:00