Script Hooks
Defines script hooks to be executed before or after a JReleaser step.
Script hooks are executed before Command Hooks. |
Configuration
Legend:
-
required
-
optional
-
may use environment variable
-
accepts Name Templates
#
hooks:
# Enable or disable all hooks.
# Supported values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
# Defaults to `ALWAYS`.
#
active: ALWAYS
# Execute scripts if the condition evaluates to `true`.
#
condition: '"{{ Env.CI }}" == true'
# A map of global environment variables.
# Accepts values from `matrix`.
#
environment:
FOO: bar
# Includes the default matrix.
#
applyDefaultMatrix: false
# Configures matrix variables.
#
matrix:
vars:
os: [ linux, osx, windows ]
arch: [ arm64, amd64 ]
rows:
- { os: linux, arch: arm64 }
- { os: linux, arch: amd64 }
- { os: osx, arch: arm64 }
- { os: osx, arch: amd64 }
- { os: windows, arch: arm64 }
- { os: windows, arch: amd64 }
#
script:
# Enable or disable all before, success, and failure hooks.
# Supported values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
# Defaults to `ALWAYS`.
#
active: ALWAYS
# Execute scripts if the condition evaluates to `true`.
#
condition: '"{{ Env.CI }}" == true'
# A map of script environment variables.
# Accepts values from `matrix`.
#
environment:
FOO: bar
# Includes the default matrix.
#
applyDefaultMatrix: false
# Configures matrix variables.
# Values will be inherited from `hooks`.
#
matrix:
vars:
os: [ linux, osx, windows ]
arch: [ arm64, amd64 ]
rows:
- { os: linux, arch: arm64 }
- { os: linux, arch: amd64 }
- { os: osx, arch: arm64 }
- { os: osx, arch: amd64 }
- { os: windows, arch: arm64 }
- { os: windows, arch: amd64 }
# The type of hook
# Valid entries are `before`, `success`, `failure`.
#
before:
# Let the release continue if the hook fails.
# Defaults to `false`.
#
- continueOnError: true
# Print script out/err to log.
# Defaults to `false`.
#
verbose: true
# Enable or disable this hook.
# Supported values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
# Defaults to `ALWAYS`.
#
active: ALWAYS
# A map of local environment vatiables.
#
environment:
FOO: bar
# Includes the default matrix.
#
applyDefaultMatrix: false
# Configures matrix variables.
# Values will be inherited from `script`.
#
matrix:
vars:
os: [ linux, osx, windows ]
arch: [ arm64, amd64 ]
rows:
- { os: linux, arch: arm64 }
- { os: linux, arch: amd64 }
- { os: osx, arch: arm64 }
- { os: osx, arch: amd64 }
- { os: windows, arch: arm64 }
- { os: windows, arch: amd64 }
# Execute the script if the condition evaluates to `true`.
#
condition: '"{{ Env.CI }}" == true'
# Shell settings for executing the script.
# Supported values are [`BASH`, `SH`, `CMD`, `PWSH`, `POWERSHELL`].
# Defaults to `BASH`.
#
shell: BASH
# The script to be invoked.
# Accepts values from `matrix`.
#
run: '{{basedir}}/notifier.sh {{event.name}} {{event.type}} {{projectVersion}}'
# Filters this hook based on the given step.
#
filter:
includes: ['release']
excludes: ['publish']
# Filters this hook based on the current platform.
# Use a `!` prefix to exclude a platform
#
platforms:
- linux
- !windows
#
[hooks]
# Enable or disable all hooks.
# Supported values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
# Defaults to `ALWAYS`.
#
active = "ALWAYS"
# Execute hooks if the condition evaluates to `true`.
#
condition = "'{{ Env.CI }}' == true"
# A map of global environment vatiables.
# Accepts values from `matrix`.
#
environment.FOO = "bar"
# Includes the default matrix.
#
applyDefaultMatrix = false
# Configures matrix variables.
#
matrix.vars.os = [ "linux", "osx", "windows" ]
matrix.vars.arch= [ "arm64", "amd64" ]
rows = [{ os = "linux", arch = "arm64" },
{ os = "linux", arch = "amd64" },
{ os = "osx", arch = "arm64" },
{ os = "osx", arch = "amd64" },
{ os = "windows", arch = "arm64" },
{ os = "windows", arch = "amd64" }]
#
[hooks.script]
# Enable or disable all before, success, and failure hooks.
# Supported values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
# Defaults to `ALWAYS`.
#
active = "ALWAYS"
# Execute scripts if the condition evaluates to `true`.
#
condition = "'{{ Env.CI }}' == true"
# A map of script environment vatiables.
#
environment.FOO = "bar"
# Includes the default matrix.
#
applyDefaultMatrix = false
# Configures matrix variables.
# Values will be inherited from `hooks`.
#
matrix.vars.os = [ "linux", "osx", "windows" ]
matrix.vars.arch= [ "arm64", "amd64" ]
rows = [{ os = "linux", arch = "arm64" },
{ os = "linux", arch = "amd64" },
{ os = "osx", arch = "arm64" },
{ os = "osx", arch = "amd64" },
{ os = "windows", arch = "arm64" },
{ os = "windows", arch = "amd64" }]
# The type of hook
# Valid entries are `before`, `success`, `failure`.
#
# Let the release continue if the hook fails.
# Defaults to `false`.
#
continueOnError = true
# Print script out/err to log.
# Defaults to `false`.
#
verbose = true
# Enable or disable this hook.
# Supported values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
# Defaults to `ALWAYS`.
#
active = "ALWAYS"
# A map of local environment vatiables.
# Accepts values from `matrix`.
#
environment.FOO = "bar"
# Includes the default matrix.
#
applyDefaultMatrix = false
# Configures matrix variables.
# Values will be inherited from `script`.
#
matrix.vars.os = [ "linux", "osx", "windows" ]
matrix.vars.arch= [ "arm64", "amd64" ]
rows = [{ os = "linux", arch = "arm64" },
{ os = "linux", arch = "amd64" },
{ os = "osx", arch = "arm64" },
{ os = "osx", arch = "amd64" },
{ os = "windows", arch = "arm64" },
{ os = "windows", arch = "amd64" }]
# Execute the script if the condition evaluates to `true`.
#
condition = "'{{ Env.CI }}' == true"
# Shell settings for executing the script.
# Supported values are [`BASH`, `SH`, `CMD`, `PWSH`, `POWERSHELL`].
# Defaults to `BASH`.
#
shell = "BASH"
# The script to be invoked.
# Accepts values from `matrix`.
#
run = "{{basedir}}/notifier.sh {{event.name}} {{event.type}} {{projectVersion}}"
# Filters this hook based on the given step.
#
filter.includes = ["release"]
filter.excludes = ["publish"]
# Filters this hook based on the current platform.
# Use a `!` prefix to exclude a platform
#
platforms = ["linux", "!windows"]
{
//
"hooks": {
// Enable or disable all hooks.
// Supported values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
// Defaults to `ALWAYS`.
//
"active": "ALWAYS",
// Execute hooks if the condition evaluates to `true`.
//
"condition": "'{{ Env.CI }}' == true",
// A map of global environment vatiables.
// Accepts values from `matrix`.
//
"environment": {
"FOO": "bar"
},
// Includes the default matrix.
//
"applyDefaultMatrix": false,
// Configures matrix variables.
//
"matrix": {
"vars": {
"os": [ "linux", "osx", "windows" ],
"arch": [ "arm64", "amd64" ]
},
"rows": [
{ "os": "linux", "arch": "arm64" },
{ "os": "linux", "arch": "amd64" },
{ "os": "osx", "arch": "arm64" },
{ "os": "osx", "arch": "amd64" },
{ "os": "windows", "arch": "arm64" },
{ "os": "windows", "arch": "amd64" }
]
},
//
"script": {
// Enable or disable all before, success, and failure hooks.
// Supported values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
// Defaults to `ALWAYS`.
//
"active": "ALWAYS",
// Execute scripts if the condition evaluates to `true`.
//
"condition": "'{{ Env.CI }}' == true",
// A map of script environment vatiables.
// Accepts values from `matrix`.
//
"environment": {
"FOO": "bar"
},
// Includes the default matrix.
//
"applyDefaultMatrix": false,
// Configures matrix variables.
// Values will be inherited from `hooks`.
//
"matrix": {
"vars": {
"os": [ "linux", "osx", "windows" ],
"arch": [ "arm64", "amd64" ]
},
"rows": [
{ "os": "linux", "arch": "arm64" },
{ "os": "linux", "arch": "amd64" },
{ "os": "osx", "arch": "arm64" },
{ "os": "osx", "arch": "amd64" },
{ "os": "windows", "arch": "arm64" },
{ "os": "windows", "arch": "amd64" }
]
},
// The type of hook
// Valid entries are `before`, `success`, `failure`.
//
"before": [
{
// Let the release continue if the hook fails.
// Defaults to `false`.
//
"continueOnError": true,
// Print script out/err to log.
// Defaults to `false`.
//
"verbose": true,
// Enable or disable this hook.
// Supported values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
// Defaults to `ALWAYS`.
//
"active": "ALWAYS",
// A map of local environment vatiables.
// Accepts values from `matrix`.
//
"environment": {
"FOO": "bar"
},
// Includes the default matrix.
//
"applyDefaultMatrix": false,
// Configures matrix variables.
// Values will be inherited from `script`.
//
"matrix": {
"vars": {
"os": [ "linux", "osx", "windows" ],
"arch": [ "arm64", "amd64" ]
},
"rows": [
{ "os": "linux", "arch": "arm64" },
{ "os": "linux", "arch": "amd64" },
{ "os": "osx", "arch": "arm64" },
{ "os": "osx", "arch": "amd64" },
{ "os": "windows", "arch": "arm64" },
{ "os": "windows", "arch": "amd64" }
]
},
// Execute the script if the condition evaluates to `true`.
//
"condition": "'{{ Env.CI }}' == true",
// Shell settings for executing the script.
// Supported values are [`BASH`, `SH`, `CMD`, `PWSH`, `POWERSHELL`].
// Defaults to `BASH`.
//
"shell": "BASH",
// The script to be invoked.
// Accepts values from `matrix`.
//
"run": "{{basedir}}/notifier.sh {{event.name}} {{event.type}} {{projectVersion}}",
// Filters this hook based on the given step.
//
"filter": {
"includes": ["release"],
"excludes": ["publish"]
},
// Filters this hook based on the current platform.
// Use a `!` prefix to exclude a platform
//
"platforms": [
"linux",
"!windows"
]
}
]
}
}
}
<jreleaser>
<!--
-->
<hooks>
<!--
Enable or disable all hooks.
Supported values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
Defaults to `ALWAYS`.
-->
<active>ALWAYS</active>
<!--
Execute hooks if the condition evaluates to `true`.
-->
<condition>"{{ Env.CI }}" == true</condition>
<!--
A map of global environment variables.
Accepts values from `matrix`.
-->
<environment>
<FOO>bar</FOO>
</environment>
<!--
Includes the default matrix.
-->
<applyDefaultMatrix>false</applyDefaultMatrix>
<!--
Configures matrix variables.
-->
<matrix>
<vars>
<os>
<e>linux</e>
<e>osx</e>
<e>windows</e>
</os>
<arch>
<e>arm64</e>
<e>amd64</e>
</arch>
</vars>
<rows>
<row>
<os>linux</os>
<arch>arm64</arch>
</row>
<row>
<os>linux</os>
<arch>amd64</arch>
</row>
<row>
<os>osx</os>
<arch>arm64</arch>
</row>
<row>
<os>osx</os>
<arch>amd64</arch>
</row>
<row>
<os>windows</os>
<arch>arm64</arch>
</row>
<row>
<os>windows</os>
<arch>amd64</arch>
</row>
</rows>
</matrix>
<!--
-->
<script>
<!--
Enable or disable all before, success, and failure hooks.
Supported values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
Defaults to `ALWAYS`.
-->
<active>ALWAYS</active>
<!--
Execute scripts if the condition evaluates to `true`.
-->
<condition>"{{ Env.CI }}" == true</condition>
<!--
A map of script environment variables.
Accepts values from `matrix`.
-->
<environment>
<FOO>bar</FOO>
</environment>
<!--
Includes the default matrix.
-->
<applyDefaultMatrix>false</applyDefaultMatrix>
<!--
Configures matrix variables.
Values will be inherited from `hooks`.
-->
<matrix>
<vars>
<os>
<e>linux</e>
<e>osx</e>
<e>windows</e>
</os>
<arch>
<e>arm64</e>
<e>amd64</e>
</arch>
</vars>
<rows>
<row>
<os>linux</os>
<arch>arm64</arch>
</row>
<row>
<os>linux</os>
<arch>amd64</arch>
</row>
<row>
<os>osx</os>
<arch>arm64</arch>
</row>
<row>
<os>osx</os>
<arch>amd64</arch>
</row>
<row>
<os>windows</os>
<arch>arm64</arch>
</row>
<row>
<os>windows</os>
<arch>amd64</arch>
</row>
</rows>
</matrix>
<!--
The type of hook
Valid entries are `before`, `success`, `failure`.
-->
<before>
<scriptHook>
<!--
Let the release continue if the hook fails.
Defaults to `false`.
-->
<continueOnError>true</continueOnError>
<!--
Print script out/err to log.
Defaults to `false`.
-->
<verbose>true</verbose>
<!--
Enable or disable this hook.
Supported values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
Defaults to `ALWAYS`.
-->
<active>ALWAYS</active>
<!--
A map of local environment variables.
Accepts values from `matrix`.
-->
<environment>
<FOO>bar</FOO>
</environment>
<!--
Includes the default matrix.
-->
<applyDefaultMatrix>false</applyDefaultMatrix>
<!--
Configures matrix variables.
Values will be inherited from `script`.
-->
<matrix>
<vars>
<os>
<e>linux</e>
<e>osx</e>
<e>windows</e>
</os>
<arch>
<e>arm64</e>
<e>amd64</e>
</arch>
</vars>
<rows>
<row>
<os>linux</os>
<arch>arm64</arch>
</row>
<row>
<os>linux</os>
<arch>amd64</arch>
</row>
<row>
<os>osx</os>
<arch>arm64</arch>
</row>
<row>
<os>osx</os>
<arch>amd64</arch>
</row>
<row>
<os>windows</os>
<arch>arm64</arch>
</row>
<row>
<os>windows</os>
<arch>amd64</arch>
</row>
</rows>
</matrix>
<!--
Execute the script if the condition evaluates to `true`.
-->
<condition>"{{ Env.CI }}" == true</condition>
<!--
Shell settings for executing the script.
Supported values are [`BASH`, `SH`, `CMD`, `PWSH`, `POWERSHELL`].
Defaults to `BASH`.
-->
<shell>BASH</shell>
<!--
The script to be invoked.
Accepts values from `matrix`.
-->
<run>{{basedir}}/notifier.sh {{event.name}} {{event.type}} {{projectVersion}}</run>
<!--
Filters this hook based on the given step.
-->
<filter>
<includes>release</includes>
<excludes>publish</excludes>
</filter>
<!--
Filters this hook based on the current platform.
Use a `!` prefix to exclude a platform
-->
<platforms>
<platform>linux</platform>
<platform>!windows</platform>
</platforms>
</scriptHook>
</before>
</script>
</hooks>
</jreleaser>
jreleaser {
//
hooks {
// Enable or disable all hooks.
// Supported values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
// Defaults to `ALWAYS`.
//
active = 'ALWAYS'
// Execute hooks if the condition evaluates to `true`.
//
condition = '"{{ Env.CI }}" == true'
// A map of global environment variables.
// Accepts values from `matrix`.
//
environment('FOO', 'bar')
// Includes the default matrix.
//
applyDefaultMatrix = false
// Configures matrix variables.
//
matrix {
variable('os', ['linux', 'osx', 'windows'])
variable('arch', ['arm64', 'amd64'])
row(os: 'linux', arch: 'arm64')
row(os: 'linux', arch: 'amd64')
row(os: 'osx', arch: 'arm64')
row(os: 'osx', arch: 'amd64')
row(os: 'windows', arch: 'arm64')
row(os: 'windows', arch: 'amd64')
}
//
script {
// Enable or disable all before, success, and failure hooks.
// Supported values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
// Defaults to `ALWAYS`.
//
active: ALWAYS
// Execute scripts if the condition evaluates to `true`.
//
condition = '"{{ Env.CI }}" == true'
// A map of script environment variables.
// Accepts values from `matrix`.
//
environment('FOO', 'bar')
// Includes the default matrix.
//
applyDefaultMatrix = false
// Configures matrix variables.
// Values will be inherited from `hooks`.
//
matrix {
variable('os', ['linux', 'osx', 'windows'])
variable('arch', ['arm64', 'amd64'])
row(os: 'linux', arch: 'arm64')
row(os: 'linux', arch: 'amd64')
row(os: 'osx', arch: 'arm64')
row(os: 'osx', arch: 'amd64')
row(os: 'windows', arch: 'arm64')
row(os: 'windows', arch: 'amd64')
}
// The type of hook
// Valid entries are `before`, `success`, `failure`.
//
before {
// Let the release continue if the hook fails.
// Defaults to `false`.
//
continueOnError = true
// Print script out/err to log.
// Defaults to `false`.
//
verbose = true
// Enable or disable this hook.
// Supported values are [`NEVER`, `ALWAYS`, `RELEASE`, `SNAPSHOT`].
// Defaults to `ALWAYS`.
//
active = 'ALWAYS'
// A map of local environment variables.
// Accepts values from `matrix`.
//
environment('FOO', 'bar')
// Includes the default matrix.
//
applyDefaultMatrix = false
// Configures matrix variables.
// Values will be inherited from `script`.
//
matrix {
variable('os', ['linux', 'osx', 'windows'])
variable('arch', ['arm64', 'amd64'])
row(os: 'linux', arch: 'arm64')
row(os: 'linux', arch: 'amd64')
row(os: 'osx', arch: 'arm64')
row(os: 'osx', arch: 'amd64')
row(os: 'windows', arch: 'arm64')
row(os: 'windows', arch: 'amd64')
}
// Execute the script if the condition evaluates to `true`.
//
condition = '"{{ Env.CI }}" == true'
// Shell settings for executing the script.
// Supported values are [`BASH`, `SH`, `CMD`, `PWSH`, `POWERSHELL`].
// Defaults to `BASH`.
//
shell = 'BASH'
// The script to be invoked.
// Accepts values from `matrix`.
//
run = "{{basedir}}/notifier.sh {{event.name}} {{event.type}} {{projectVersion}}"
// Filters this hook based on the given step.
//
filter {
includes = ["release"]
excludes = ["publish"]
}
// Filters this hook based on the current platform.
// Use a `!` prefix to exclude a platform
//
platform('linux')
platform('!windows')
}
}
}
}
Environment
When not explicitly set, the value of the following properties may be resolved from an environment variable or a system property as shown in the table. The system property takes precedence over the environment variable.
System Property | Environment Variable |
---|---|
active |
|
jreleaser.hooks.script.active |
JRELEASER_HOOKS_SCRIPT_ACTIVE |
Before hooks
System Property | Environment Variable |
---|---|
active |
|
jreleaser.hooks.script.before.${index}.active |
JRELEASER_HOOKS_SCRIPT_BEFORE_${index}_ACTIVE |
Success hooks
System Property | Environment Variable |
---|---|
active |
|
jreleaser.hooks.script.success.${index}.active |
JRELEASER_HOOKS_SCRIPT_SUCCESS_${index}_ACTIVE |
Failure hooks
System Property | Environment Variable |
---|---|
active |
|
jreleaser.hooks.script.failure.${index}.active |
JRELEASER_HOOKS_SCRIPT_FAILURE_${index}_ACTIVE |
Step Names
The following step names may be used when filtering hooks:
-
session
-
download
-
assemble
-
changelog
-
catalog
-
checksum
-
sign
-
upload
-
deploy
-
release
-
prepare
-
package
-
publish
-
announce
Template Names
The following template names are also available:
{{event.type}} |
One of [ |
{{event.name}} |
One of the previously mentioned steps. |
{{event.stacktrace}} |
Full stacktrace (if any) when |
Shell
The default shell is BASH
. The shell command that is run internally executes a temporary file that contains the commands
specified in the run
property. The following shell expressions will be used depending on the set value of the shell
property:
Shell | Description | Expression |
---|---|---|
BASH |
JReleaser appends the extension |
|
SH |
JReleaser appends the extension |
|
CMD |
The extension |
|
PWSH |
The PowerShell Core. JReleaser appends the extension |
|
POWERSHELL |
The PowerShell Desktop. JReleaser appends the extension |
|
Fail Fast
BASH
sets set -eo pipefail
by default while SH
does not. In PWSH
and POWERSHELL
JReleaser prepends
$ErrorActionPreference = 'stop'
to script contents. It also appends if Test-Path -LiteralPath variable:\LASTEXITCODE { exit $LASTEXITCODE }
to powershell scripts to reflect the script’s last exit code.
Environment Resolution
Environment variables may be defined at 3 different scopes: global
, script
, and local
. Precedence when resolving keys
goes from most specific scope to the most generic.
hooks:
environment:
KEY1: global1
KEY2: global2
KEY3: global3
script:
environment:
KEY2: script1
KEY4: script2
KEY5: script3
before:
- run: |
echo "KEY1: $KEY1"
echo "KEY2: $KEY2"
echo "KEY3: $KEY3"
echo "KEY4: $KEY4"
echo "KEY5: $KEY5"
echo "KEY6: $KEY6"
verbose: true
environment:
KEY3: local1
KEY5: local2
KEY6: local3
Executing the script results in the following output
[hooks] KEY1: global1
[hooks] KEY2: script1
[hooks] KEY3: local1
[hooks] KEY4: script2
[hooks] KEY5: local2
[hooks] KEY6: local3
Conditions
You may define a condition to determine if the script should run or not. Name Templates will be evaluated before the actual condition. Expressions follow JEXL rules:
The following example shows a script hook used to run the build before the assemble
step only if the running environment
has an environment variable CI
set to true, which is typically the case in Continuous Integration services:
hooks:
script:
before:
- run: './mvnw -ntp verify'
condition: '"{{ Env.CI }}" == true'
verbose: true
filter:
includes: ['assemble']
Use quotes around name templates if their evaluation may result in an empty string. |
Output
Script hooks have the option to provide key/value pairs as input for other steps in the current workflow. Simply
use JRELEASER_OUTPUT:
as prefix in the script’s output followed by key=value
. For example, the following configuration
adds a key named foo
with a value bar
before the changelog
step is invoked:
hooks:
script:
before:
- filter:
includes: [changelog]
run: 'echo JRELEASER_OUTPUT:foo=bar'