Search code examples
githubazure-pipelinesgithub-actionsgithub-enterprisegithub-release

How to release an Azure DevOps artifact on GitHub Enterprise releases?


I like to release a pipeline artifact on GitHub Enterprise releases.

Here is the article I followed.

https://www.logitblog.com/releasing-an-azure-devops-artifact-on-github-releases/

The problem is that the "GitHubRelease" task is not compatible with GitHub Enterprise.

see this issue: https://github.com/microsoft/azure-pipelines-tasks/issues/11570

Any workaround to implement this function, like a script.

///////////////////////////////////////////////////////

Here is the bash task I used, but the task failed with this: ##[error]Bash exited with code '3'.

- task: Bash@3
  inputs:
    targetType: 'inline'
    script: |
      # Set the variables
      repo="client/SysInfo" # The repository name
      token=$(GithubToken) # Your personal access token
      tag="v1.0.0" # The tag name for the release
      title="My first release" # The title for the release
      body="This is a test release" # The description for the release
      file="README.md" # The path to the file to upload
      
      # Create the release
      url="https://github.azc.ext.xx.com/client/SysInfo/releases"
      response=$(curl -s -X POST -H "Authorization: token $token" -H "Content-Type: application/json" -d "{\"tag_name\":\"$tag\",\"name\":\"$title\",\"body\":\"$body\"}" $url)
      
      # Get the upload URL
      upload_url=$(echo $response | jq -r '.upload_url' | sed 's/{.*}//')
      
      # Upload the file
      curl -s -X POST -H "Authorization: token $token" -H "Content-Type: application/octet-stream" --data-binary @"$file" "$upload_url?name=$file"

Solution

  • You can use rest api create-a-release which support for github enterprise for the script.

    enter image description here

    I don't have github enterprise on hand, so i checked for github with rest api, sample code below, but it should work for enterprise as well(change the url).

    - task: Bash@3
      inputs:
        targetType: 'inline'
        script: |
          # Set the variables
          repo="owner/repo3" # The repository name
          token=$(githubtoken) # Your personal access token
          tag="v1.0.0" # The tag name for the release
          title="My first release" # The title for the release
          body="This is a test release" # The description for the release
          file="README.md" # The path to the file to upload
          
          # Create the release
          url="https://api.github.com/repos/$repo/releases"
          response=$(curl -s -X POST -H "Authorization: token $token" -H "Content-Type: application/json" -d "{\"tag_name\":\"$tag\",\"name\":\"$title\",\"body\":\"$body\"}" $url)
          
          # Get the upload URL
          upload_url=$(echo $response | jq -r '.upload_url' | sed 's/{.*}//')
          
          # Upload the file
          curl -s -X POST -H "Authorization: token $token" -H "Content-Type: application/octet-stream" --data-binary @"$file" "$upload_url?name=$file"
    

    enter image description here