Custom Shell Commands with @semantic-release/exec
Use @semantic-release/exec to run custom shell commands at each stage of the semantic-release lifecycle. Execute build scripts, deploy commands, notifications, and more.
Detailed Explanation
Running Custom Commands During Release
The @semantic-release/exec plugin lets you execute arbitrary shell commands at each step of the semantic-release lifecycle. This is the most flexible plugin for integrating with custom build systems, deployment tools, or notification services.
Configuration
{
"branches": ["main"],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
["@semantic-release/exec", {
"verifyConditionsCmd": "test -f Dockerfile",
"prepareCmd": "npm run build && echo ${nextRelease.version} > VERSION",
"publishCmd": "./scripts/deploy.sh ${nextRelease.version}",
"successCmd": "curl -X POST https://hooks.slack.com/services/xxx -d '{"text": "Released v${nextRelease.version}"}'",
"failCmd": "curl -X POST https://hooks.slack.com/services/xxx -d '{"text": "Release failed!"}'"
}],
"@semantic-release/github"
]
}
Lifecycle Hooks
Each command runs at a specific point in the release process:
| Hook | When It Runs |
|---|---|
verifyConditionsCmd |
Before anything else — validates prerequisites |
analyzeCommitsCmd |
During commit analysis |
verifyReleaseCmd |
After release type is determined |
generateNotesCmd |
During release notes generation |
prepareCmd |
Before publishing — build, bundle, etc. |
publishCmd |
The actual publish step |
successCmd |
After successful release |
failCmd |
If the release fails |
Template Variables in Commands
All commands have access to environment variables:
${nextRelease.version}— the new version (e.g.,1.2.3)${nextRelease.type}— major, minor, or patch${nextRelease.channel}— the release channel${lastRelease.version}— the previous version
Multiple Exec Plugins
You can include multiple instances of the exec plugin if different commands need to run at different stages with different failure handling.
Use Case
Projects that need to integrate semantic-release with custom deployment scripts, Docker builds, Slack or Teams notifications, CDN cache invalidation, database migrations, or any other process not covered by standard plugins.
Try It — Semantic Release Config Builder
Related Topics
Docker Image Release with semantic-release
Advanced Configuration
Basic npm Package Release with semantic-release
Basic Configuration
GitHub Release with Uploaded Assets
Advanced Configuration
Monorepo semantic-release Configuration
Advanced Configuration
semantic-release Without npm Publishing
Plugin Configuration