Chocolatey

Publishes packages to https://chocolatey.org.

At the moment, only artifacts with .zip extension may be packaged with Chocolatey.

Local publication of packages requires running on Windows, have powershell and choco installed. If you rather package and push on CI then set remoteBuild to true.

Publication of snapshots is not allowed.

Legend:

  • required

  • optional

  • may use environment variable

  • accepts Name Templates

  • YAML

  • TOML

  • JSON

  • Maven

  • Gradle

# 
packagers:
  # 
  chocolatey:
    # Enables or disables Chocolatey.
    # Valid values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
    # Defaults to `NEVER`.
    # 
    active: ALWAYS

    # Let the release continue if the packager fails.
    # Defaults to `false`.
    # 
    continueOnError: true

    # Additional properties used when evaluating templates.
    #  
    extraProperties:
      # Key will be capitalized and prefixed with `chocolatey`, i.e, `chocolateyFoo`.
      foo: bar

    # Directory with file templates used to prepare the Chocolatey distribution.
    # Defaults to `src/jreleaser/distributions/${distribution.name}/chocolatey`.
    # If specified, path must exist.
    # 
    templateDirectory: path/to/chocolatey/templates

    # Git author used to commit to the repository.
    # 
    commitAuthor:
      # Name used when authoring commits.
      # Defaults to `jreleaserbot`.
      # 
      name: jreleaserbot

      # E-mail used when authoring commits.
      # Defaults to `jreleaser@kordamp.org`.
      # 
      email: jreleaser@kordamp.org

    # Git repository to push the manifest to.
    # Defaults are shown.
    # 
    bucket:
      # Enables or disables the bucket.
      # Valid values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
      # Defaults to `RELEASE`.
      # 
      active: ALWAYS


      # The owner of the bucket.
      # Defaults to the same owner as the release repository.
      # 
      owner: duke

      # The name of the bucket.
      # Defaults to `chocolatey-bucket`.
      # 
      name: chocolatey-bucket

      # The target branch to use.
      # May define a `JRELEASER_CHOCOLATEY_${GIT}_BRANCH` environment variable instead.
      # Defaults to the branch pointed by HEAD.
      #  
      branch: HEAD

      # Username used for authoring commits. Must have write access to the bucket.
      # If left unspecified, the `JRELEASER_CHOCOLATEY_${GIT}_USERNAME`
      # environment variable must be defined.
      # Defaults to the same username as the release repository.
      #  
      username: duke

      # Password or OAuth token with write access to the bucket.
      # If left unspecified, the `JRELEASER_CHOCOLATEY_${GIT}_TOKEN`
      # environment variable must be defined.
      #  
      token: __DO_NOT_SET_HERE__

      # Message when committing to the bucket.
      # If left unspecified, `{{distributionName}} {{tagName}}` will be used.
      #  
      commitMessage: '{{distributionName}} {{tagName}}'

    # The username that can publish Chocolatey packages.
    # If left unspecified, the release owner will be used.
    # 
    username: duke

    # The ApiKey associated with the given account.
    # If left unspecified, the `JRELEASER_CHOCOLATEY_API_KEY`
    # environment variable must be defined.
    #  
    apiKey: __DO_NOT_SET_HERE__

    # Whether to build the package on a remote server or locally.
    # Defaults to `false`.
    # 
    remoteBuild: false

    # The title of the spec.
    # If left unspecified, will use `${project.name}`.
    # 
    title: Duke
# 
[packagers.chocolatey]
  # Enables or disables Chocolatey.
  # Valid values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
  # Defaults to `NEVER`.
  # 
  active = "ALWAYS"

  # Let the release continue if the packager fails.
  # Defaults to `false`.
  # 
  continueOnError = true

  # Additional properties used when evaluating templates.
  #  
  extraProperties.foo = "bar"
  # Key will be capitalized and prefixed with `chocolatey`, i.e, `chocolateyFoo`.

  # Directory with file templates used to prepare the Chocolatey distribution.
  # Defaults to `src/jreleaser/distributions/${distribution.name}/chocolatey`.
  # If specified, path must exist.
  # 
  templateDirectory = "path/to/chocolatey/templates"

  # Git author used to commit to the repository.

  # Name used when authoring commits.
  # Defaults to `jreleaserbot`.
  # 
  commitAuthor.name = "jreleaserbot"

  # E-mail used when authoring commits.
  # Defaults to `jreleaser@kordamp.org`.
  # 
  commitAuthor.email = "jreleaser@kordamp.org"

  # Git repository to push the manifest to.
  # Defaults are shown.

  # Enables or disables the bucket.
  # Valid values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
  # Defaults to `RELEASE`.
  # 
  bucket.active = "ALWAYS"


  # The owner of the bucket.
  # Defaults to the same owner as the release repository.
  # 
  bucket.owner = "duke"

  # The name of the bucket.
  # Defaults to `chocolatey-bucket`.
  # 
  bucket.name = "chocolatey-bucket"

  # The target branch to use.
  # May define a `JRELEASER_CHOCOLATEY_${GIT}_BRANCH` environment variable instead.
  # Defaults to the branch pointed by HEAD.
  #  
  bucket.branch = "HEAD"

  # Username used for authoring commits. Must have write access to the bucket.
  # If left unspecified, the `JRELEASER_CHOCOLATEY_${GIT}_USERNAME`
  # environment variable must be defined.
  # Defaults to the same username as the release repository.
  #  
  bucket.username = "duke"

  # Password or OAuth token with write access to the bucket.
  # If left unspecified, the `JRELEASER_CHOCOLATEY_${GIT}_TOKEN`
  # environment variable must be defined.
  #  
  bucket.token = "__DO_NOT_SET_HERE__"

  # Message when committing to the bucket.
  # If left unspecified, `{{distributionName}} {{tagName}}` will be used.
  #  
  bucket.commitMessage = "{{distributionName}} {{tagName}}"

  # The username that can publish Chocolatey packages.
  # If left unspecified, the release owner will be used.
  # 
  username = "duke"

  # The ApiKey associated with the given account.
  # If left unspecified, the `JRELEASER_CHOCOLATEY_API_KEY`
  # environment variable must be defined.
  #  
  apiKey = "__DO_NOT_SET_HERE__"

  # Whether to build the package on a remote server or locally.
  # Defaults to `false`.
  # 
  remoteBuild = false

  # The title of the spec.
  # If left unspecified, will use `${project.name}`.
  # 
  title = "Duke"
{
  // 
  "packagers": {
    // 
    "chocolatey": {
      // Enables or disables Chocolatey.
      // Valid values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
      // Defaults to `NEVER`.
      // 
      "active": "ALWAYS",

      // Let the release continue if the packager fails.
      // Defaults to `false`.
      // 
      "continueOnError": true,

      // Additional properties used when evaluating templates.
      //  
      "extraProperties": {
        // Key will be capitalized and prefixed with `chocolatey`, i.e, `chocolateyFoo`.
        "foo": "bar"
      },

      // Directory with file templates used to prepare the Chocolatey distribution.
      // Defaults to `src/jreleaser/distributions/${distribution.name}/chocolatey`.
      // If specified, path must exist.
      // 
      "templateDirectory": "path/to/chocolatey/templates",

      // Git author used to commit to the repository.
      // 
      "commitAuthor": {
        // Name used when authoring commits.
        // Defaults to `jreleaserbot`.
        // 
        "name": "jreleaserbot",

        // E-mail used when authoring commits.
        // Defaults to `jreleaser@kordamp.org`.
        // 
        "email": "jreleaser@kordamp.org"
      },

      // Git repository to push the manifest to.
      // Defaults are shown.
      // 
      "bucket": {
        // Enables or disables the bucket.
        // Valid values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
        // Defaults to `RELEASE`.
        // 
        "active": "ALWAYS",


        // The owner of the bucket.
        // Defaults to the same owner as the release repository.
        // 
        "owner": "duke",

        // The name of the bucket.
        // Defaults to `chocolatey-bucket`.
        // 
        "name": "chocolatey-bucket",

        // The target branch to use.
        // May define a `JRELEASER_CHOCOLATEY_${GIT}_BRANCH` environment variable instead.
        // Defaults to the branch pointed by HEAD.
        //  
        "branch": "HEAD",

        // Username used for authoring commits. Must have write access to the bucket.
        // If left unspecified, the `JRELEASER_CHOCOLATEY_${GIT}_USERNAME`
        // environment variable must be defined.
        // Defaults to the same username as the release repository.
        //  
        "username": "duke",

        // Password or OAuth token with write access to the bucket.
        // If left unspecified, the `JRELEASER_CHOCOLATEY_${GIT}_TOKEN`
        // environment variable must be defined.
        //  
        "token": "__DO_NOT_SET_HERE__",

        // Message when committing to the bucket.
        // If left unspecified, `{{distributionName}} {{tagName}}` will be used.
        //  
        "commitMessage": "{{distributionName}} {{tagName}}"
      },

      // The username that can publish Chocolatey packages.
      // If left unspecified, the release owner will be used.
      // 
      "username": "duke",

      // The ApiKey associated with the given account.
      // If left unspecified, the `JRELEASER_CHOCOLATEY_API_KEY`
      // environment variable must be defined.
      //  
      "apiKey": "__DO_NOT_SET_HERE__",

      // Whether to build the package on a remote server or locally.
      // Defaults to `false`.
      // 
      "remoteBuild": false,

      // The title of the spec.
      // If left unspecified, will use `${project.name}`.
      // 
      "title": "Duke"
    }
  }
}
<jreleaser>
  <!--
    
  -->
  <packagers>
    <!--
      
    -->
    <chocolatey>
      <!--
        Enables or disables Chocolatey.
        Valid values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
        Defaults to `NEVER`.
        
      -->
      <active>ALWAYS</active>

      <!--
        Let the release continue if the packager fails.
        Defaults to `false`.
        
      -->
      <continueOnError>true</continueOnError>

      <!--
        Additional properties used when evaluating templates.
         
      -->
      <extraProperties>
        <!--
          Key will be capitalized and prefixed with `chocolatey`, i.e, `chocolateyFoo`.
        -->
        <foo>bar</foo>
      </extraProperties>

      <!--
        Directory with file templates used to prepare the Chocolatey distribution.
        Defaults to `src/jreleaser/distributions/${distribution.name}/chocolatey`.
        If specified, path must exist.
        
      -->
      <templateDirectory>path/to/chocolatey/templates</templateDirectory>

      <!--
        Git author used to commit to the repository.
        
      -->
      <commitAuthor>

        <!--
           Name used when authoring commits.
          Defaults to `jreleaserbot`.
          
        -->
        <name>jreleaserbot</name>

        <!--
          E-mail used when authoring commits.
          Defaults to `jreleaser@kordamp.org`.
          
        -->
        <email>jreleaser@kordamp.org</email>
      </commitAuthor>

      <!--
        Git repository to push the manifest to.
        Defaults are shown.
        
      -->
      <bucket>
        <!--
          Enables or disables the bucket.
          Valid values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
          Defaults to `RELEASE`.
          
        -->
        <active>ALWAYS</active>


        <!--
          The owner of the bucket.
          Defaults to the same owner as the release repository.
          
        -->
        <owner>duke</owner>

        <!--
          The name of the bucket.
          Defaults to `chocolatey-bucket`.
          
        -->
        <name>chocolatey-bucket</name>

        <!--
          The target branch to use.
          May define a `JRELEASER_CHOCOLATEY_${GIT}_BRANCH`` environment variable instead.
          Defaults to the branch pointed by HEAD.
           
        -->
        <branch>HEAD</branch>

        <!--
          Username used for authoring commits. Must have write access to the bucket.
          If left unspecified, the `JRELEASER_CHOCOLATEY_${GIT}_USERNAME`
          environment variable must be defined.
          Defaults to the same username as the release repository.
           
        -->
        <username>duke</username>

        <!--
          Password or OAuth token with write access to the bucket.
          If left unspecified, the `JRELEASER_CHOCOLATEY_${GIT}_TOKEN`
          environment variable must be defined.
           
        -->
        <token>__DO_NOT_SET_HERE__</token>

        <!--
          Message when committing to the bucket.
          If left unspecified, `{{distributionName}} {{tagName}}` will be used.
           
        -->
        <commitMessage>{{distributionName}} {{tagName}}</commitMessage>
      </bucket>

      <!--
        The username that can publish Chocolatey packages.
        If left unspecified, the release owner will be used.
        
      -->
      <username>duke</username>

      <!--
        The ApiKey associated with the given account.
        If left unspecified, the `JRELEASER_CHOCOLATEY_API_KEY`
        environment variable must be defined.
         
      -->
      <apiKey>__DO_NOT_SET_HERE__</apiKey>

      <!--
        Whether to build the package on a remote server or locally.
        Defaults to `false`.
        
      -->
      <remoteBuild>false</remoteBuild>

      <!--
        The title of the spec.
        If left unspecified, will use `${project.name}`.
        
      -->
      <title>Duke</title>
    </chocolatey>
  </packagers>
</jreleaser>
jreleaser {
  // 
  packagers {
    // 
    chocolatey {
      // Enables or disables Chocolatey.
      // Valid values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
      // Defaults to `NEVER`.
      // 
      active = 'ALWAYS'

      // Let the release continue if the packager fails.
      // Defaults to `false`.
      // 
      continueOnError = true

      // Additional properties used when evaluating templates.
      // Key will be capitalized and prefixed with `chocolatey`, i.e, `chocolateyFoo`.
      //  
      extraProperties.put('foo', 'bar')

      // Directory with file templates used to prepare the Chocolatey distribution.
      // Defaults to `src/jreleaser/distributions/${distribution.name}/chocolatey`.
      // If specified, path must exist.
      // 
      templateDirectory = 'path/to/chocolatey/templates'

      // Git author used to commit to the repository.
      // 
      commitAuthor {
        // Name used when authoring commits.
        // Defaults to `jreleaserbot`.
        // 
        name = 'jreleaserbot'

        // E-mail used when authoring commits.
        // Defaults to `jreleaser@kordamp.org`.
        // 
        email = 'jreleaser@kordamp.org'
      }

      // Git repository to push the manifest to.
      // Defaults are shown.
      // 
      bucket {
        // Enables or disables the bucket.
        // Valid values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
        // Defaults to `RELEASE`.
        // 
        active = 'ALWAYS'


        // The owner of the bucket.
        // Defaults to the same owner as the release repository.
        // 
        owner = 'duke'

        // The name of the bucket.
        // Defaults to `chocolatey-bucket`.
        // 
        name = 'chocolatey-bucket'

        // The target branch to use.
        // May define a `JRELEASER_BRANCH` environment variable instead.
        // Defaults to the branch pointed by HEAD.
        //  
        branch = 'HEAD'

        // Username used for authoring commits. Must have write access to the bucket.
        // If left unspecified, the `JRELEASER_CHOCOLATEY_${GIT}_USERNAME`
        // environment variable must be defined.
        // Defaults to the same username as the release repository.
        //  
        username = 'duke'

        // Password or OAuth token with write access to the bucket.
        // If left unspecified, the `JRELEASER_CHOCOLATEY_${GIT}_TOKEN`
        // environment variable must be defined.
        //  
        token = '__DO_NOT_SET_HERE__'

        # Message when committing to the bucket.
        # If left unspecified, `{{distributionName}} {{tagName}}` will be used.
        #  
        commitMessage = '{{distributionName}} {{tagName}}'
      }

      // The username that can publish Chocolatey packages.
      // If left unspecified, the release owner will be used.
      // 
      username = 'duke'

      // The ApiKey associated with the given account.
      // If left unspecified, the `JRELEASER_CHOCOLATEY_API_KEY`
      // environment variable must be defined.
      //  
      apiKey = '__DO_NOT_SET_HERE__'

      // Whether to build the package on a remote server or locally.
      // Defaults to `false`.
      // 
      remoteBuild = false

      // The title of the spec.
      // If left unspecified, will use `${project.name}`.
      // 
      title = 'Duke'
    }
  }
}

Template files may be initialized using the template command.

The bucket token environment variable must match with the chosen Release service, that is, it must be one of [JRELEASER_CHOCOLATEY_GITHUB_TOKEN, JRELEASER_CHOCOLATEY_GITLAB_TOKEN, JRELEASER_CHOCOLATEY_GITEA_TOKEN].

Assuming that the current version is 1.2.3, and a distribution named app, the above configuration will generate the following files which will be published to duke/chocolatey-bucket/app

app.nuspec
<?xml version="1.0" encoding="utf-8"?>
<!-- Do not remove this test for UTF-8: if “Ω” doesn’t appear as greek uppercase omega letter enclosed in quotation marks, you should use an editor that supports UTF-8, not this one. -->
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
  <metadata>
    <!-- required -->
    <id>app</id>
    <version>1.2.3</version>
    <authors>Duke</authors>
    <description>Sample app</description>
    <!-- optional -->
    <title>app</title>
    <projectUrl>https://acme.com/app</projectUrl>
    <licenseUrl>https://github.com/duke/app/blob/main/LICENSE</licenseUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <tags>app</tags>
    <summary>Sample app</summary>
    <releaseNotes>https://github.com/duke/app/releases/tag/v1.2.3</releaseNotes>
  </metadata>
  <files>
    <file src="tools\**" target="tools" />
  </files>
</package>
tools/chocolateyinstall.ps1
$tools = Split-Path $MyInvocation.MyCommand.Definition
$package = Split-Path $tools
$app_home = Join-Path $package 'app-1.2.3'
$app_bat = Join-Path $app_home 'bin/app.bat'

Install-ChocolateyZipPackage `
    -PackageName 'app' `
    -Url 'https://github.com/duke/app/releases/download/v1.2.3/app-1.2.3.zip' `
    -Checksum '812121a64bbd3f49286f7b0be3c9209068f71fcf9541f313708979602e8de466' `
    -ChecksumType 'sha256' `
    -UnzipLocation $package

Install-BinFile -Name 'app' -Path $app_bat
tools/chocolateyuninstall.ps1
$tools = Split-Path $MyInvocation.MyCommand.Definition
$package = Split-Path $tools
$app_home = Join-Path $package 'app-1.2.3'
$app_bat = Join-Path $app_home 'bin/app.bat'

Uninstall-BinFile -Name 'app' -Path $app_bat

Templates

The default location for templates is:

src/jreleaser/distributions/<distribution-name>/chocolatey

The following list shows the filenames that may be used to override default templates:

  • binary.nuspec.tpl

  • tools/chocolateyinstall.ps1.tpl

  • tools/chocolateyuninstall.ps1.tpl

Any additional files found in the template directories will be copied as is unless their filename ends with .tpl in which case Name Templates substitution will take place.

Templates may be initialized using the template command