fredrik
fredrik

Reputation: 10291

How to create GitHub release with Azure Pipelines yml?

I am building Python wheels in my public GitHub repository using Azure Pipelines. I successfully add those as build artifacts in my .yml:

- task: PublishBuildArtifacts@1
  inputs:
    pathtoPublish: '$(Build.ArtifactStagingDirectory)'
    artifactName: drop

I would now like to generate a GitHub release with these wheels.


Attempt #1: create

I have tried to create a new release, by adding the GitHub Release task to my .yml

- task: GithubRelease@0
  inputs:
    gitHubConnection: 'my-connection'
    repositoryName: 'my-repo'
    action: 'create'
    target: '$(build.sourceVersion)'
    tagSource: 'auto'
    assets: '$(Build.ArtifactStagingDirectory)/*'
    assetUploadMode: 'replace'

This gives me an error when it runs on a new commit:

2019-01-30T10:54:13.4154988Z ##[section]Starting: GitHubRelease
2019-01-30T10:54:13.4159417Z ==============================================================================
2019-01-30T10:54:13.4159489Z Task         : GitHub Release
2019-01-30T10:54:13.4159535Z Description  : Create, edit, or delete a GitHub release.
2019-01-30T10:54:13.4159592Z Version      : 0.0.2
2019-01-30T10:54:13.4159631Z Author       : Microsoft Corporation
2019-01-30T10:54:13.4159688Z Help         : [More Information](https://aka.ms/AA3aeiw)
2019-01-30T10:54:13.4159733Z ==============================================================================
2019-01-30T10:54:13.8077592Z 4482b84d-9af2-47ea-ba55-e92f0e856217 exists true
2019-01-30T10:54:13.8078191Z Fetching the tag for target: cd14aa02e85823d52f61d1e5e2fccc307e1504f8
2019-01-30T10:54:14.1969398Z ##[error]An unexpected error occurred while fetching tags.
2019-01-30T10:54:14.1978761Z ##[error]Error: Not Found
2019-01-30T10:54:14.1982593Z ##[section]Finishing: GitHubRelease

I am doing this is a non-master branch, but I don't think that is the cause of the error above?

Attempt #2: edit

Since I don't really want releases to be made on every single commit or GitHub PR, I would like to instead trigger this on every time e.g. a tag is pushed.

So, I thought, okay, let's see if maybe changing the action to "edit" works better... and so I changed the .yml to say:

- task: GithubRelease@0
inputs:
    gitHubConnection: 'my-connection'
    repositoryName: 'my-repo'
    action: 'edit'
    target: '$(build.sourceVersion)'
    tagSource: 'auto'
    tag: '1.0'
    assets: '$(Build.ArtifactStagingDirectory)/*'
    assetUploadMode: 'replace'

Then ran the following (with my 'github-release' branch checked out):

git commit -am "Try 1.0"
git tag -am "Adding tag 1.0" 1.0
git push origin 1.0 HEAD:refs/heads/github-release

But now when I check the CI, I see this on the GitHub release task:

2019-01-30T11:28:52.8639389Z ##[section]Starting: GitHubRelease
2019-01-30T11:28:52.8643449Z ==============================================================================
2019-01-30T11:28:52.8643522Z Task         : GitHub Release
2019-01-30T11:28:52.8643585Z Description  : Create, edit, or delete a GitHub release.
2019-01-30T11:28:52.8643632Z Version      : 0.0.2
2019-01-30T11:28:52.8643688Z Author       : Microsoft Corporation
2019-01-30T11:28:52.8643752Z Help         : [More Information](https://aka.ms/AA3aeiw)
2019-01-30T11:28:52.8643802Z ==============================================================================
2019-01-30T11:28:53.2645821Z 4482b84d-9af2-47ea-ba55-e92f0e856217 exists true
2019-01-30T11:28:53.2646587Z Computing changes made in this release...
2019-01-30T11:28:53.2646657Z Fetching the latest published release...
2019-01-30T11:28:53.7121952Z No releases are published yet in the repository.
2019-01-30T11:28:53.7122209Z Fetching the initial commit...
2019-01-30T11:28:53.8614586Z ##[error]An unexpected error occurred while fetching the initial commit.
2019-01-30T11:28:53.8616507Z ##[error]Error: Not Found
2019-01-30T11:28:53.8654236Z ##[section]Finishing: GitHubRelease

What am I doing wrong?

Upvotes: 1

Views: 1746

Answers (1)

fredrik
fredrik

Reputation: 10291

The documentation says that tagSource can be set to either 'auto' or 'manual', but I came across a website saying 'Git tag' was a value, so I tried that. Turns out that worked better:

- task: GithubRelease@0
  inputs:
    gitHubConnection: 'my-connection'
    repositoryName: 'username/my-repo'
    action: 'edit'
    target: '$(build.sourceVersion)'
    tagSource: 'Git tag'
    tag: '1.0'
    assetUploadMode: 'replace'

I had previously also only entered my repo name, not username/repo.

Upvotes: 1

Related Questions