Work with Versions
Create, update, release, and archive the versions in a space.
HAPI's versions module manages the versions in a space: creating them, changing their dates, and moving them through their lifecycle by releasing or archiving them.
Pattern for working with versions with HAPI
The pattern for working with versions is:
- Import the
versionsmodule. - Call the function inside an exported async function.
- Pass a space key or ID when listing or creating, and a version ID for everything else.
import * as Versions from '@scriptrunnerhq/hapi/versions'
export default async function () {
// Create a version in a space
const version = await Versions.create({
name: '2.1.0',
projectId: 10000,
description: 'Spring release',
})
// Release it
await Versions.release(version.id)
return version.name
}Note:
getAll returns results page by page rather than as a single array, so use for await to work through them. See the HAPI landing page for how to iterate results.Available functions
| Function | Description |
|---|---|
getAll(spaceKeyOrId, options?) | Every version in a space, page by page. Filter with query, or with status set to released, unreleased or archived |
getById(versionId) | A single version, or nothing if it does not exist |
create(options) | Create a version |
update(versionId, options) | Change a version's name, description, or dates |
release(version) | Mark a version released |
archive(version) | Archive a version |
deleteVersion(version) | Delete a version |
Tip:
release, archive and deleteVersion accept either a version ID or a version object, so you can pass the result of getById or create straight in.In-app example scripts
The following example is available in-app from the Example scripts modal:
- Copy versions to a new space: copy all versions from one space to another, preserving each version's name, description, start date, and release date.