Screwdriver models
Asynchronous methods return promises.
npm install screwdriver-models
'use strict';
const Model = require('screwdriver-models');
const factory = Model.PipelineFactory.getInstance({
datastore,
scm
});
const config = {
params: {
scmUri: 'github.com:12345:banana'
},
paginate {
page: 2,
count: 3
},
sort: 'ascending',
sortBy: 'scmRepo.name'
}
factory.list(config).then(pipelines => {
// Do stuff with list of pipelines
});
Parameter | Type | Description |
---|---|---|
config | Object | Config Object |
config.paginate.page | Number | The page for pagination |
config.paginate.count | Number | The count for pagination |
config.params | Object | Fields to search on |
config.raw | Boolean | Whether to return raw data or not |
config.search | Object | Search parameters |
config.search.field | String or Array | Search field(s) (e.g.: jobName) |
config.search.keyword | String | Search keyword (e.g.: %PR-%) |
config.sort | String | Order to sort by (ascending or descending ) |
config.sortBy | String | Key to sort by (default id ) |
factory.create(config).then(model => {
// do stuff with pipeline model
});
Parameter | Type | Required | Description |
---|---|---|---|
config | Object | Yes | Configuration Object |
config.admins | Object | Yes | Admins for this pipeline, e.g { batman: true } |
config.scmUri | String | Yes | Source Code URI for the application |
config.scmContext | String | Yes | Scm context to which user belongs |
Get a pipeline based on id. Can pass the generatedId for the pipeline, or the unique keys for the model, and the id will be determined automatically.
factory.get(id).then(model => {
// do stuff with pipeline model
});
factory.get({ scmUri }).then(model => {
// do stuff with pipeline model
});
Parameter | Type | Description |
---|---|---|
id | Number | The unique ID for the pipeline |
config.scmUri | String | Source Code URI for the application |
Update a specific pipeline model
model.update()
Example:
'use strict';
const Model = require('screwdriver-models');
const factory = Model.PipelineFactory.getInstance({
datastore,
scm
});
const scmUri = 'github.com:12345:master';
factory.get({ scmUri }).then(model => {
model.scmUri = 'github.com:12345:foo';
return model.update();
})
Attach Screwdriver webhook to the pipeline's repository
model.addWebhook(webhookUrl)
Parameter | Type | Description |
---|---|---|
webhookUrl | String | The webhook url to be added |
Sync the pipeline. Look up the configuration in the repo to create and delete jobs if necessary.
model.sync()
Get the screwdriver configuration for the pipeline at the given ref
model.getConfiguration(config)
Parameter | Type | Required | Description |
---|---|---|---|
ref | String | No | Reference to the branch or PR |
Return a list of jobs that belong to this pipeline
model.getJobs(config)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
config | Object | No | Configuration Object | |
config.params | Object | No | Fields to search on | |
config.paginate.page | Number | No | The page for pagination | |
config.paginate.count | Number | No | The count for pagination |
Return a list of events that belong to this pipeline
model.getEvents(config)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
config | Object | No | Config Object | |
config.type | Number | No | pipeline |
Type of event: pipeline or pr |
config.sort | String | No | descending |
Order to sort by (ascending or descending ) |
Get the pipeline's access tokens
model.tokens
.then((tokens) => {
// do stuff with tokens
});
Get all the event durations for this pipeline within time range
model.getMetrics()
.then((metrics) => {
// do stuff with metrics
});
'use strict';
const Model = require('screwdriver-models');
const factory = Model.JobFactory.getInstance({
datastore
});
const config = {
params: {
pipelineId: 1
},
paginate {
page: 2,
count: 3
}
}
factory.list(config).then(jobs => {
// Do stuff with list of jobs
});
Parameter | Type | Description |
---|---|---|
config | Object | Configuration Object |
config.paginate.page | Number | The page for pagination |
config.paginate.count | Number | The count for pagination |
config.params | Object | fields to search on |
factory.create(config).then(model => {
// do stuff with job model
});
Parameter | Type | Description |
---|---|---|
config | Object | Configuration Object |
config.pipelineId | Number | The pipelineId that the job belongs to |
config.name | String | The name of the job |
Get a job based on id. Can pass the generatedId for the job, or the unique keys for the model, and the id will be determined automatically.
factory.get(id).then(model => {
// do stuff with job model
});
factory.get({ pipelineId, name }).then(model => {
// do stuff with job model
});
Parameter | Type | Description |
---|---|---|
id | Number | The unique ID for the job |
config.pipelineId | Number | Id of the pipeline the job is associated with |
config.name | String | Name of the job |
'use strict';
const Model = require('screwdriver-models');
const factory = Model.JobFactory.getInstance({
datastore
});
factory.get(id).then(model => {
model.name = 'hello';
return model.update();
});
Update a job
model.update()
Return builds that belong to this job
model.getBuilds(config)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
config | Object | No | Configuration Object | |
config.sort | String | No | descending | ascending or descending |
Return all running builds that belong to this jobId
model.getRunningBuilds()
Get all the build durations for this job within time range
model.getMetrics()
.then((metrics) => {
// do stuff with metrics
});
'use strict';
const Model = require('screwdriver-models');
const factory = Model.BuildFactory.getInstance({
datastore,
scm,
executor,
uiUri
});
const config = {
params: {
jobId: 4
},
paginate {
page: 2,
count: 3
}
}
factory.list(config).then(builds => {
// Do stuff with list of builds
});
Parameter | Type | Description |
---|---|---|
config | Object | Config Object |
config.paginate.page | Number | The page for pagination |
config.paginate.count | Number | The count for pagination |
config.params | Object | fields to search on |
factory.create(config).then(model => {
// do stuff with build model
});
Parameter | Type | Required | Description |
---|---|---|---|
config | Object | Yes | Configuration Object |
config.apiUri | String | Yes | URI back to the API |
config.tokenGen | Function | Yes | Generator for building tokens |
config.username | String | Yes | User who made the change to kick off the build |
config.scmContext | String | Yes | Scm context to which user belongs |
config.container | String | No | Container for the build to run in |
config.sha | String | No | SHA used to kick off the build |
config.prRef | String | No | PR branch or reference; required for PR jobs |
config.eventId | Number | No | Id of the event this build belongs to |
Get a build based on id. Can pass the generatedId for the build, or the unique keys for the model, and the id will be determined automatically.
factory.get(id).then(model => {
// do stuff with build model
});
factory.get({ jobId, number }).then(model => {
// do stuff with build model
});
Parameter | Type | Description |
---|---|---|
id | Number | The unique ID for the build |
config.jobId | Number | The unique ID for a job |
config.number | Number | build number |
Get the statuses of the newest builds of jobs based on job ids (in ascending order). Can specify the number of build statuses desired per job id, this defaults to 1. Can specify the number of build statuses to skip per job id, this defaults to 0.
factory.getBuildStatuses(config).then(statuses => {
// do stuff with the statuses
});
Parameter | Type | Required | Description |
---|---|---|---|
config | Object | Yes | Configuration Object |
config.jobIds | Array | Yes | Ids of the jobs to get build statuses for |
config.numBuilds | Number | No | Number of build statuses to return per job |
config.offset | Number | No | Number of build statuses to skip per job |
Get the latest builds for each job in corresponding groupEventId.
factory.getLatestBuilds(config).then(latestBuilds => {
// do stuff with the latest builds
});
Parameter | Type | Required | Description |
---|---|---|---|
config | Object | Yes | Configuration Object |
config.groupEventId | Number | Yes | Group event ID to get latest builds for |
'use strict';
const Model = require('screwdriver-models');
const factory = Model.BuildFactory.getInstance({
datastore,
scm,
executor,
uiUri
});
factory.get(id).then(model => {
model.state = 'FAILURE';
model.update();
});
Update a specific build
model.update()
Stream the log of a build
model.stream()
Update a commit status
model.updateCommitStatus(pipeline)
Parameter | Type | Description |
---|---|---|
pipeline | Pipeline | The pipeline that this build belongs to |
Start the build and update commit status as pending
model.start()
model.stop()
model.isDone()
'use strict';
const Model = require('screwdriver-models');
const factory = Model.UserFactory.getInstance({
datastore,
scm,
password // Password to seal/unseal user's token
});
const config = {
params: {
username: 'batman',
scmContext: 'github:github.com'
},
paginate {
page: 2,
count: 3
}
}
factory.list(config).then(users => {
// Do stuff with list of users
});
Parameter | Type | Description |
---|---|---|
config | Object | Config Object |
config.paginate.page | Number | The page for pagination |
config.paginate.count | Number | The count for pagination |
config.params | Object | fields to search on |
factory.create(config).then(model => {
// do stuff with user model
});
Parameter | Type | Required | Description |
---|---|---|---|
config | Object | Yes | Configuration Object |
config.username | String | Yes | User who made the change to kick off the build |
config.token | String | Yes | unsealed token |
config.scmContext | String | Yes | Scm context to which user belongs |
config.password | String | Yes | User's password used to seal/unseal token, not saved in datastore |
Get a user based on id. Can pass the generatedId for the user, or the username, and the id will be determined automatically. Can also pass a Screwdriver access token, and will get the user associated with that token.
factory.get(id).then(model => {
// do stuff with user model
});
factory.get({ username }).then(model => {
// do stuff with user model
});
factory.get({ token }).then(model => {
// do stuff with user model
});
Parameter | Type | Description |
---|---|---|
id | Number | The unique ID for the build |
config.username | String | User name |
config.scmContext | String | Scm context to which user belongs |
config.accessToken | String | A user access token value |
'use strict';
const Model = require('screwdriver-models');
const factory = Model.UserFactory.getInstance({
datastore,
scm,
password // Password to seal/unseal user's token
});
const config = {
username: 'myself',
token: 'eyJksd3', // User's github token
scmContext: 'github:github.com', // Scm context to which user belongs
password
}
factory.create(config)
.then(user => user.getPermissions(scmUri))
.then(permissions => {
// do stuff here
});
Update a specific user
model.update()
Seal a token
model.sealToken(token)
Parameter | Type | Description |
---|---|---|
token | String | The token to seal |
Unseal the user's token
model.unsealToken()
Get user's permissions for a specific repo
model.getPermissions(scmUri)
Parameter | Type | Description |
---|---|---|
scmUri | String | The scmUri of the repo |
Get the user's access tokens
model.tokens
.then((tokens) => {
// do stuff with tokens
});
'use strict';
const Model = require('screwdriver-models');
const factory = Model.SecretFactory.getInstance({
datastore,
password // Password for encryption operations
});
const config = {
params: {
pipelineId: 1
},
paginate {
page: 2,
count: 3
}
}
factory.list(config).then(secrets => {
// Do stuff with list of secrets
});
Parameter | Type | Description |
---|---|---|
config | Object | Config Object |
config.paginate.page | Number | The page for pagination |
config.paginate.count | Number | The count for pagination |
config.params | Object | fields to search on |
factory.create(config).then(model => {
// do stuff with secret model
});
Parameter | Type | Required | Description |
---|---|---|---|
config | Object | Yes | Configuration Object |
config.pipelineId | Number | Yes | Pipeline that this secret belongs to |
config.name | String | Yes | Secret name |
config.value | String | Yes | Secret value |
config.allowInPR | String | Yes | Flag to denote if this secret can be shown in PR builds |
Get a secret based on id. Can pass the generatedId for the secret, or the combination of pipelineId and secret name, and the id will be determined automatically.
factory.get(id).then(model => {
// do stuff with secret model
});
factory.get({ pipelineId, name }).then(model => {
// do stuff with secret model
});
Parameter | Type | Description |
---|---|---|
id | Number | The unique ID for the build |
config.pipelineId | Number | Pipeline that the secret belongs to |
config.name | String | Secret name |
'use strict';
const Model = require('screwdriver-models');
const factory = Model.SecretFactory.getInstance({
datastore,
password // Password for encryption operations
});
const config = {
pipelineId: 1,
name: 'NPM_TOKEN',
value: banana,
allowInPR: false
}
factory.create(config)
.then(model => // do something
});
Update a specific secret
model.update()
factory.create(config).then(model => {
// do stuff with stage model
});
Parameter | Type | Required | Description |
---|---|---|---|
config | Object | Yes | Configuration Object |
config.pipelineId | Number | Yes | Pipeline that this stage belongs to |
config.name | String | Yes | Stage name |
config.jobIds | Array | No | Jobs IDs that belong to this stage. Default [] . |
config.groupEventId | Number | Yes | Group event ID that this stage belongs to |
config.description | String | No | Description for stage |
Get stage based on ID.
factory.get(id).then(model => {
// do stuff with stage model
});
Parameter | Type | Description |
---|---|---|
id | Number | The unique ID for the stage |
List stages that have pipelineId as 12345
and groupEventId as 555
factory.list({
params: {
pipelineId: 12345,
groupEventId: 555
}
}).then(recs =>
// do things with the records
);
'use strict';
const Model = require('screwdriver-models');
const factory = Model.EventFactory.getInstance({
datastore,
scm
});
const config = {
params: {
pipelineId: 1
}
}
factory.list(config).then(events => {
// Do stuff with list of events
});
Parameter | Type | Description |
---|---|---|
config | Object | Config Object |
config.params | Object | fields to search on |
factory.create(config).then(model => {
// do stuff with event model
});
Parameter | Type | Required | Description |
---|---|---|---|
config | Object | Yes | Configuration Object |
config.type | String | No | Event type: pipeline or pr |
config.pipelineId | Number | Yes | Unique identifier of pipeline |
config.sha | String | Yes | Commit sha that the event was based on |
config.workflowGraph | Object | No | Workflow graph of the pipeline, with edges and nodes |
config.username | String | Yes | Username of the user that creates this event |
config.causeMessage | String | No | Message that describes why the event was created |
Get an event based on id. Can pass the generatedId for the event, or { pipelineId, sha } and the id will be determined automatically.
factory.get(id).then(model => {
// do stuff with event model
});
factory.get({ pipelineId, sha }).then(model => {
// do stuff with event model
});
Parameter | Type | Description |
---|---|---|
id | Number | The unique ID for the build |
config.pipelineId | Number | Unique identifier of pipeline |
config.sha | String | Commit sha that the event was based on |
'use strict';
const Model = require('screwdriver-models');
const factory = Model.EventFactory.getInstance({
datastore,
scm
});
const config = {
pipelineId: 1,
sha: 'ccc49349d3cffbd12ea9e3d41521480b4aa5de5f',
workflowGraph: {
nodes: [
{ name: '~pr' },
{ name: '~commit' },
{ name: 'main' },
{ name: 'publish' }
],
edges: [
{ src: '~pr', dest: 'main' },
{ src: '~commit', dest: 'main' },
{ src: 'main', dest: 'publish' }
]
},
username: 'stjohn',
causeMessage: 'Merge pull request #26 from screwdriver-cd/models'
}
factory.create(config)
.then(model => { // do something
});
Example event model that got created:
{
"type": "pipeline",
"pipelineId": "1",
"sha": "ccc49349d3cffbd12ea9e3d41521480b4aa5de5f",
"createTime": "2038-01-19T03:14:08.131Z",
"commit": {
"url": "https://link.to/commitDiff",
"message": "some commit message that is here",
"author": {
"avatar": "https://avatars.githubusercontent.com/u/1234567?v=3",
"name": "Batman",
"url": "https://internal-ghe.mycompany.com/imbatman",
"username": "imbatman"
}
},
"workflowGraph": {
"nodes": [
{ "name": "~pr" },
{ "name": "~commit" },
{ "name": "main" },
{ "name": "publish" }
],
"edges": [
{ "src": "~pr", "dest": "main" },
{ "src": "~commit", "dest": "main" },
{ "src": "main", "dest": "publish" }
]
},
"causeMessage": "Merge pull request #26 from screwdriver-cd/models",
"creator": {
"avatar": "https://avatars.githubusercontent.com/u/2042?v=3",
"name": "St John",
"url": "https://github.com/stjohn",
"username": "stjohn"
}
}
Update a specific event
model.update()
Get builds that belong to this event
model.getBuilds()
Get all the build durations for this event within time range
model.getMetrics()
.then((metrics) => {
// do stuff with metrics
});
'use strict';
const Model = require('screwdriver-models');
const factory = Model.TemplateFactory.getInstance({
datastore
});
const config = {
name: 'testTemplate',
namespace: 'templateNamespace', // optional
version: '1.3',
description: 'I am a test template',
maintainer: '[email protected]',
scmUri: 'github:123:master',
config: { image: 'node:6'},
labels: ['beta', 'stable']
}
factory.create(config)
.then(model => { // do something
});
Update a specific template
model.update()
factory.create(config).then(model => {
// do stuff with template model
});
Parameter | Type | Required | Description |
---|---|---|---|
config | Object | Yes | Configuration Object |
config.name | String | Yes | The template name |
config.namespace | String | No | The template namespace |
config.version | String | Yes | Version of the template |
config.description | String | Yes | Description of the template |
config.maintainer | Array | Yes | Maintainer's email |
config.config | Object | Yes | Config of the screwdriver-template.yaml |
config.pipelineId | Number | Yes | pipelineId of the template |
config.labels | Array | No | Labels attached to the template |
Get a template based on id or other params.
factory.get(id).then(model => {
// do stuff with template model
});
factory.get({ namespace, name }).then(model => {
// do stuff with template model
});
Parameter | Type | Description |
---|---|---|
id | Number | The unique ID for the Template |
config.namespace | String | Template namespace |
config.name | String | Template name (can include namespace) |
config.version | String | Template version |
Get the latest template by name or get a specific template using name and version or name and tag. The version can be in any valid version format: either major, major.minor, or major.minor.patch. If no version is specified, the function will resolve with the latest version published. If no match is found, the function will resolve null.
factory.getTemplate(fullTemplateName).then(model => {
// do stuff with template model
});
Parameter | Type | Required | Description |
---|---|---|---|
fullTemplateName | String | Yes | Name of the template and the version or tag (e.g. chef/[email protected] or chef/publish@latest). Can also be just name of the template (e.g. chef/publish) |
'use strict';
const Model = require('screwdriver-models');
const factory = Model.TemplateFactory.getInstance({
datastore
});
const config = {
params: {
name: 'chef/publish'
},
paginate {
page: 1,
count: 3
},
getCount: true
}
factory.list(config).then(templates => {
// Do stuff with list of templates
});
Parameter | Type | Description |
---|---|---|
config | Object | Config Object |
config.paginate.page | Number | The page for pagination |
config.paginate.count | Number | The count for pagination |
config.params | Object | fields to search on |
config.getCount | Boolean | Total count of record matching search param |
'use strict';
const Model = require('screwdriver-models');
const factory = Model.TemplateTagFactory.getInstance({
datastore
});
const config = {
name: 'testTemplate',
namespace: 'templateNamespace', // optional
tag: 'stable',
version: '1.3'
}
factory.create(config)
.then(model => { // do something
});
Update a specific template tag
// update template version value
model.version = '2.4';
model.update();
factory.create(config).then(model => {
// do stuff with template tag model
});
Parameter | Type | Required | Description |
---|---|---|---|
config | Object | Yes | Configuration Object |
config.name | String | Yes | The template name |
config.namespace | String | No | The template namespace |
config.tag | String | Yes | The template tag (e.g. stable, latest, etc) |
config.version | String | Yes | Version of the template |
Get a template tag based on id.
factory.get(id).then(model => {
// do stuff with template model
});
factory.get({ namespace, name }).then(model => {
// do stuff with template model
});
Parameter | Type | Description |
---|---|---|
id | Number | The unique ID for the Template tag |
config.namespace | String | Template namespace |
config.name | String | Template name (can include namespace) |
'use strict';
const Model = require('screwdriver-models');
const factory = Model.TemplateTagFactory.getInstance({
datastore
});
const config = {
params: {
name: 'chef/publish'
},
paginate {
page: 1,
count: 3
}
}
factory.list(config).then(templateTags => {
// Do stuff with list of templateTags
});
Parameter | Type | Description |
---|---|---|
config | Object | Config Object |
config.paginate.page | Number | The page for pagination |
config.paginate.count | Number | The count for pagination |
config.params | Object | fields to search on |
'use strict';
const Model = require('screwdriver-models');
const factory = Model.TriggerFactory.getInstance({
datastore
});
const config = {
dest: '~sd@123:component',
src: '~sd@456:main'
}
factory.create(config)
.then(model => { // do something
});
factory.create(config).then(model => {
// do stuff with trigger model
});
Parameter | Type | Required | Description |
---|---|---|---|
config | Object | Yes | Configuration Object |
config.src | String | Yes | The job that initiates the trigger (ex: ~sd@123:component) |
config.dest | String | Yes | The job that is triggered (ex: ~sd@456:main) |
Get trigger based on id.
factory.get(id).then(model => {
// do stuff with trigger model
});
Parameter | Type | Description |
---|---|---|
id | Number | The unique ID for the trigger |
List triggers that have dest as ~sd@456:main
// update template version value
factory.list({
params: {
dest: '~sd@456:main'
}
}).then(recs =>
// do things with the records
);
Get destinations based on source trigger.
// update template version value
factory.getDestFromSrc('~sd@456:main').then(dests =>
console.log(dests);
// [destA, destB]
);
Parameter | Type | Description |
---|---|---|
src | String | The job that initiates the trigger (ex: ~sd@123:component) |
Get triggers based on pipeline ID.
factory.getTriggers({ pipelineId, type }).then(result => {
console.log(result);
// [{
// jobName1,
// triggers: [destA, destB]
// }, {
// jobName2,
// triggers: [destC, destD]
// }]
});
Parameter | Type | Description |
---|---|---|
config | Object | Config object |
config.pipelineId | Number | The unique ID for the pipeline |
config.type | String | Type of jobs to get (pr or pipeline ; default pipeline ) |
'use strict';
const Model = require('screwdriver-models');
const factory = Model.TokenFactory.getInstance({
datastore
});
const config = {
params: {
userId: 12345
},
paginate {
page: 1,
count: 3
}
}
factory.list(config).then(tokens => {
// Do stuff with list of tokens
});
Parameter | Type | Description |
---|---|---|
config | Object | Config Object |
config.paginate.page | Number | The page for pagination |
config.paginate.count | Number | The count for pagination |
config.params | Object | fields to search on |
factory.create(config).then(model => {
// do stuff with token model
});
Parameter | Type | Required | Description |
---|---|---|---|
config | Object | Yes | Configuration Object |
config.userId | Number | Yes | User that this token belongs to |
config.name | String | Yes | Token name |
config.description | String | No | Description of the token |
Get a token based on id. Can pass the generatedId for the token, or the token value, and the id will be determined automatically.
factory.get(id).then(model => {
// do stuff with token model
});
factory.get({ value }).then(model => {
// do stuff with token model
});
Parameter | Type | Description |
---|---|---|
id | Number | The unique ID for the token |
config.value | String | The value of the token |
'use strict';
const Model = require('screwdriver-models');
const factory = Model.TokenFactory.getInstance({
datastore,
});
const config = {
userId: 12345,
name: 'NPM_TOKEN',
description: 'A token for use by npm'
}
factory.create(config)
.then(model => // do something
});
Update a specific token
model.update()
Refresh a token's value while preserving its other metadata. Attaches a temporary "value" field to the model
token.refresh()
.then(model => // do something with the new model.value
});
'use strict';
const Model = require('screwdriver-models');
const factory = Model.CollectionFactory.getInstance({
datastore
});
const config = {
params: {
userId: 12345
}
};
factory.list(config).then(collections => {
// Do stuff with list of collections
});
Parameter | Type | Description |
---|---|---|
config | Object | Config object |
config.params | Object | Fields to search on |
factory.create(config).then(model => {
// do stuff with collection model
});
Parameter | Type | Required | Description |
---|---|---|---|
config | Object | Yes | Configuration Object |
config.userId | Number | Yes | User that this collection belongs to |
config.name | String | Yes | Collection name |
config.description | String | No | Collection description |
config.pipelineIds | Array | No | List of ids of pipelines associated with this collection |
Get a collection based on unique id of collection. Can also pass in a combination of userId and collection name, and the id will be determined automatically.
factory.get(id).then(model => {
// do stuff with collection model
});
factory.get({ userId, name }).then(model => {
// do stuff with collection model
})
Parameter | Type | Description |
---|---|---|
id | Number | The unique id for the collection |
'use strict';
const Model = require('screwdriver-models');
const factory = Model.CollectionFactory.getInstance({
datastore
});
const config = {
userId: 12345,
name: 'Screwdriver',
description: 'Collection of screwdriver pipelines'
};
factory.create(config)
.then(model => {
// do something with model
});
Update a specific collection
model.update()
Remove a specific collection
model.remove()
'use strict';
const Model = require('screwdriver-models');
const factory = Model.CommandFactory.getInstance({
datastore
});
const config = {
namespace: 'testCommandNS',
name: 'testCommand',
version: '1.3',
description: 'This is a test command',
maintainer: '[email protected]',
format: 'habitat',
habitat: {
mode: 'remote',
package: 'core/git/2.14.1',
command: 'git'
}
}
factory.create(config)
.then(model => { // do something
});
factory.create(config).then(model => {
// do stuff with command model
});
Parameter | Type | Required | Description |
---|---|---|---|
config | Object | Yes | Configuration Object |
config.namespace | String | Yes | The command namespace |
config.name | String | Yes | The command name |
config.version | String | Yes | Version of the command |
config.description | String | Yes | Description of the command |
config.usage | String | No | Command usage and arguments (e.g.: 'sd-cmd exec foo/bar@1 -d -h ') |
config.maintainer | String | Yes | Maintainer's email |
config.format | String | Yes | Format of the command, habitat or docker or binary |
config.habitat | Object | Yes (any one of habitat, docker, binary) | Configuration Object for Habitat command |
config.docker | Object | Yes (any one of habitat, docker, binary) | Configuration Object for Docker command |
config.binary | Object | Yes (any one of habitat, docker, binary) | Configuration Object for Binary command |
Get a command based on id.
factory.get(id).then(model => {
// do stuff with command model
});
Parameter | Type | Description |
---|---|---|
id | Number | The unique ID for the Command |
Get the latest command by name or get a specific command using namespace, command name and version or tag. The version can be in any valid version format: either major, major.minor, or major.minor.patch. If no version is specified, the function will resolve with the latest version published. If no match is found, the function will resolve null.
factory.getCommand(fullCommandName).then(model => {
// do stuff with command model
});
Parameter | Type | Required | Description |
---|---|---|---|
fullCommandName | String | Yes | Namespace and name of the command and the version or tag (e.g. chefdk/[email protected] or chefdk/knife@latest). Can also be just namespace and name of the command (e.g. chefdk/knife) |
'use strict';
const Model = require('screwdriver-models');
const factory = Model.CommandTagFactory.getInstance({
datastore
});
const config = {
namespace: 'testCommandNS',
name: 'testCommand',
tag: 'stable',
version: '1.3.5'
}
factory.create(config)
.then(model => { // do something
});
Update a specific command tag
// update command version value
model.version = '2.4.8';
model.update()
factory.create(config).then(model => {
// do stuff with command tag model
});
Parameter | Type | Required | Description |
---|---|---|---|
config | Object | Yes | Configuration Object |
config.namespace | String | Yes | The command namespace |
config.name | String | Yes | The command name |
config.tag | String | Yes | The command tag (e.g. stable, latest, etc) |
config.version | String | Yes | Exact version of the command |
Get a command tag based on id.
factory.get(id).then(model => {
// do stuff with command model
});
Parameter | Type | Description |
---|---|---|
id | Number | The unique ID for the Command Tag |
'use strict';
const Model = require('screwdriver-models');
const factory = Model.BannerFactory.getInstance({
datastore
});
const config = {
params: {
isActive: true
}
};
factory.list(config).then(banners => {
// Do stuff with list of banners
});
Parameter | Type | Description |
---|---|---|
config | Object | Config object |
config.params | Object | Fields to search on |
factory.create(config).then(model => {
// do stuff with banner model
});
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
config | Object | Yes | Configuration Object | |
config.message | String | Yes | Text of banner to be displayed | |
config.isActive | Boolean | No | false | Flag for whether banner should display |
config.type | String | No | info | Type/Severity of banner message. Options: info ,warn |
config.createdBy | String | Yes | Username of the user creating the banner |
Get a banner based on unique id of banner.
factory.get(id).then(model => {
// do stuff with banner model
});
Parameter | Type | Description |
---|---|---|
id | Number | The unique id for the banner |
'use strict';
const Model = require('screwdriver-models');
const factory = Model.BannerFactory.getInstance({
datastore
});
const config = {
message: 'There will be a brief outage between 9:00am and 9:15am tomorrow morning',
isActive: true,
type: 'info'
};
factory.create(config)
.then(model => {
// do something with model
});
Update a specific banner
model.update()
Remove a specific banner
model.remove()
'use strict';
const Model = require('screwdriver-models');
const factory = Model.BuildClusterFactory.getInstance({
datastore
});
const config = {
params: {
isActive: true
}
};
factory.list(config).then(buildclusters => {
// Do stuff with list of buildclusters
});
Parameter | Type | Description |
---|---|---|
config | Object | Config object |
config.params | Object | Fields to search on |
factory.create(config).then(model => {
// do stuff with buildCluster model
});
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
config | Object | Yes | Configuration Object | |
config.name | String | Yes | Name of the build cluster (unique constraint) | |
config.description | String | No | Description of the build cluster | |
config.scmContext | String | Yes | SCM context | |
config.scmOrganizations | Array | Yes | SCM organizations that can use the build cluster | |
config.isActive | Boolean | No | false | Flag for whether banner should display |
config.managedByScrewdriver | Boolean | Yes | Flag for whether the cluster managed by Screwdriver | |
config.maintainer | String | Yes | Email of the maintainer | |
config.weightage | String | No | 100 | Weight percentage for build cluster (from 1 to 100) |
Get a buildcluster based on unique id of buildcluster.
factory.get(id).then(model => {
// do stuff with buildcluster model
});
Parameter | Type | Description |
---|---|---|
id | Number | The unique id for the buildcluster |
'use strict';
const Model = require('screwdriver-models');
const factory = Model.BuildClusterFactory.getInstance({
datastore
});
const config = {
name: 'sd',
scmContext: 'github:github.com',
scmOrganizations: [],
isActive: true,
managedByScrewdriver: true,
maintainer: '[email protected]'
};
factory.create(config)
.then(model => {
// do something with model
});
Update a specific BuildCluster
model.update()
Remove a specific BuildCluster
model.remove()
npm test
Code licensed under the BSD 3-Clause license. See LICENSE file for terms.