Skip to content

Repository files navigation

Screwdriver Models

VersionDownloadsBuild StatusOpen IssuesDependency StatusLicense

Screwdriver models

Usage

Asynchronous methods return promises.

npm install screwdriver-models

Pipeline Factory

Search

'use strict';constModel=require('screwdriver-models');constfactory=Model.PipelineFactory.getInstance({
datastore,
scmPlugin
});constconfig={params: {configUrl: 'banana'},paginate{page: 2,count: 3}}factory.list(config).then(pipelines=>{// Do stuff with list of pipelines});
ParameterTypeDescription
configObjectConfig Object
config.paginate.pageNumberThe page for pagination
config.paginate.countNumberThe count for pagination
config.paramsObjectfields to search on

Create

factory.create(config).then(model=>{// do stuff with pipeline model});
ParameterTypeRequiredDescription
configObjectYesConfiguration Object
config.adminsObjectYesAdmins for this pipeline, e.g { batman: true }
config.scmUrlStringYesSource Code URL for the application
config.configUrlStringNoSource Code URL for Screwdriver configuration

Get

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({ scmUrl }).then(model=>{// do stuff with pipeline model});
ParameterTypeDescription
idStringThe unique ID for the pipeline
config.scmUrlStringSource Code URL for the application

Pipeline Model

Update

Update a specific pipeline model

model.update()

Example:

'use strict';constModel=require('screwdriver-models');constfactory=Model.PipelineFactory.getInstance({
datastore,
scmPlugin
});constscmUrl='git@git.corp.yahoo.com:foo/BAR.git';factory.get({ scmUrl }).then(model=>{model.configUrl='git@git.corp.yahoo.com:foo/bar.git#master';returnmodel.update();})

Sync

Sync the pipeline. Look up the configuration in the repo to create and delete jobs if necessary.

model.sync()

Format the Scm Url

Format the scm url. Will make the scm url lower case and add a #master branch name if a branch name is not already specified.

model.formatScmUrl(scmUrl)
ParameterTypeRequiredDescription
scmUrlStringYesGithub scm url

Example:

'use strict';constModel=require('screwdriver-models');constfactory=Model.PipelineFactory.getInstance({
datastore,
scmPlugin
});constscmUrl='git@git.corp.yahoo.com:foo/BAR.git';factory.get({ scmUrl }).then(model=>{constformattedScmUrl=model.formatScmUrl(model.scmUrl);console.log(formattedScmUrl);// Prints 'git@git.corp.yahoo.com:foo/bar.git#master'})

Job Factory

Search

'use strict';constModel=require('screwdriver-models');constfactory=Model.JobFactory.getInstance({
datastore
});constconfig={params: {pipelineId: 'aabbccdd1234'},paginate{page: 2,count: 3}}factory.list(config).then(jobs=>{// Do stuff with list of jobs});
ParameterTypeDescription
configObjectConfig Object
config.paginate.pageNumberThe page for pagination
config.paginate.countNumberThe count for pagination
config.paramsObjectfields to search on

Create

factory.create(config).then(model=>{// do stuff with job model});
ParameterTypeDescription
configObjectConfiguration Object
config.pipelineIdStringThe pipelineId that the job belongs to
config.nameStringThe name of the job

Get

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});
ParameterTypeDescription
idStringThe unique ID for the job
config.pipelineIdStringId of the pipeline the job is associated with
config.nameString Name of the job

Job Model

'use strict';constModel=require('screwdriver-models');constfactory=Model.JobFactory.getInstance({
datastore
});factory.get(id).then(model=>{model.name='hello';returnmodel.update();});

Update

Update a job

model.update()

Build Factory

Search

'use strict';constModel=require('screwdriver-models');constfactory=Model.BuildFactory.getInstance({ datastore,
scmPlugin,
executor,
uiUri
});constconfig={params: {jobId: 'aaabbccdd1234'},paginate{page: 2,count: 3}}factory.list(config).then(builds=>{// Do stuff with list of builds});
ParameterTypeDescription
configObjectConfig Object
config.paginate.pageNumberThe page for pagination
config.paginate.countNumberThe count for pagination
config.paramsObjectfields to search on

Create

factory.create(config).then(model=>{// do stuff with build model});
ParameterTypeRequiredDescription
configObjectYesConfiguration Object
config.apiUriStringYesURI back to the API
config.tokenGenFUnctionYesGenerator for building tokens
config.usernameStringYesUser who made the change to kick off the build
config.containerStringNoContainer for the build to run in
config.shaStringNoSHA used to kick off the build

Get

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});
ParameterTypeDescription
idStringThe unique ID for the build
config.jobIdStringThe unique ID for a job
config.numberNumberbuild number

Build Model

'use strict';constModel=require('screwdriver-models');constfactory=Model.BuildFactory.getInstance({ datastore,
scmPlugin,
executor,
uiUri
});factory.get(id).then(model=>{model.state='FAILURE';model.update();});

Update

Update a specific build

model.update()

Stream

Stream the log of a build

model.stream()

User Factory

Search

'use strict';constModel=require('screwdriver-models');constfactory=Model.UserFactory.getInstance({
datastore,
scmPlugin,
password // Password to seal/unseal user's token});constconfig={params: {username: 'batman'},paginate{page: 2,count: 3}}factory.list(config).then(users=>{// Do stuff with list of users});
ParameterTypeDescription
configObjectConfig Object
config.paginate.pageNumberThe page for pagination
config.paginate.countNumberThe count for pagination
config.paramsObjectfields to search on

Create

factory.create(config).then(model=>{// do stuff with user model});
ParameterTypeRequiredDescription
configObjectYesConfiguration Object
config.usernameStringYesUser who made the change to kick off the build
config.tokenStringYesunsealed token
config.passwordStringYesUser's password used to seal/unseal token, not saved in datastore

Get

Get a user based on id. Can pass the generatedId for the user, or the username, and the id will be determined automatically.

factory.get(id).then(model=>{// do stuff with user model});factory.get({ username }).then(model=>{// do stuff with user model});
ParameterTypeDescription
idStringThe unique ID for the build
config.usernameStringUser name

User Model

'use strict';constModel=require('screwdriver-models');constfactory=Model.UserFactory.getInstance({
datastore,
scmPlugin,
password // Password to seal/unseal user's token});constconfig={username: 'myself',token: 'eyJksd3',// User's github token
password
}factory.create(config).then(user=>user.getPermissions(scmUrl)).then(permissions=>{// do stuff here});

Update

Update a specific user

model.update()

Seal Token

Seal a token

model.sealToken(token)
ParameterTypeDescription
tokenStringThe token to seal

Unseal Token

Unseal the user's token

model.unsealToken()

Get User's Permissions For a Repo

Get user's permissions for a specific repo

model.getPermissions(scmUrl)
ParameterTypeDescription
scmUrlStringThe scmUrl of the repo

Secret Factory

Search

'use strict';constModel=require('screwdriver-models');constfactory=Model.SecretFactory.getInstance({
datastore,
password // Password for encryption operations});constconfig={params: {pipelineId: '2d991790bab1ac8576097ca87f170df73410b55c'},paginate{page: 2,count: 3}}factory.list(config).then(secrets=>{// Do stuff with list of secrets});
ParameterTypeDescription
configObjectConfig Object
config.paginate.pageNumberThe page for pagination
config.paginate.countNumberThe count for pagination
config.paramsObjectfields to search on

Create

factory.create(config).then(model=>{// do stuff with secret model});
ParameterTypeRequiredDescription
configObjectYesConfiguration Object
config.pipelineIdStringYesPipeline that this secret belongs to
config.nameStringYesSecret name
config.valueStringYesSecret value
config.allowInPRStringYesFlag to denote if this secret can be shown in PR builds

Get

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});
ParameterTypeDescription
idStringThe unique ID for the build
config.pipelineIdStringPipeline that the secret belongs to
config.nameStringSecret name

Secret Model

'use strict';constModel=require('screwdriver-models');constfactory=Model.SecretFactory.getInstance({
datastore,
password // Password for encryption operations});constconfig={pipelineId: '2d991790bab1ac8576097ca87f170df73410b55c',name: 'NPM_TOKEN',value: banana,allowInPR: false}factory.create(config).then(model=>// do something});

Update

Update a specific secret

model.update()

Testing

npm test

License

Code licensed under the BSD 3-Clause license. See LICENSE file for terms.

About

Screwdriver Models

Resources

Contributing

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages