Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including screwdriver-models with all npm packages installed. Try it out:

var screwdriverModels = require("screwdriver-models")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

screwdriver-models v28.2.0

Screwdriver models

Screwdriver Models

Version Downloads Build Status Open Issues Dependency Status License

Screwdriver models

Usage

Asynchronous methods return promises.

npm install screwdriver-models

Pipeline Factory

Search

'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
});
ParameterTypeDescription
configObjectConfig Object
config.paginate.pageNumberThe page for pagination
config.paginate.countNumberThe count for pagination
config.paramsObjectFields to search on
config.rawBooleanWhether to return raw data or not
config.searchObjectSearch parameters
config.search.fieldString or ArraySearch field(s) (e.g.: jobName)
config.search.keywordStringSearch keyword (e.g.: %PR-%)
config.sortStringOrder to sort by (ascending or descending)
config.sortByStringKey to sort by (default id)

Create

factory.create(config).then(model => {
    // do stuff with pipeline model
});
ParameterTypeRequiredDescription
configObjectYesConfiguration Object
config.adminsObjectYesAdmins for this pipeline, e.g { batman: true }
config.scmUriStringYesSource Code URI for the application
config.scmContextStringYesScm context to which user belongs

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({ scmUri }).then(model => {
    // do stuff with pipeline model
});
ParameterTypeDescription
idNumberThe unique ID for the pipeline
config.scmUriStringSource Code URI for the application

Pipeline Model

Update

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();
})

Add Screwdriver webhook

Attach Screwdriver webhook to the pipeline's repository

model.addWebhook(webhookUrl)
ParameterTypeDescription
webhookUrlStringThe webhook url to be added

Sync

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

model.sync()

Get Configuration

Get the screwdriver configuration for the pipeline at the given ref

model.getConfiguration(config)
ParameterTypeRequiredDescription
refStringNoReference to the branch or PR

Get Jobs

Return a list of jobs that belong to this pipeline

model.getJobs(config)
ParameterTypeRequiredDefaultDescription
configObjectNoConfiguration Object
config.paramsObjectNoFields to search on
config.paginate.pageNumberNoThe page for pagination
config.paginate.countNumberNoThe count for pagination

Get Events

Return a list of events that belong to this pipeline

model.getEvents(config)
ParameterTypeRequiredDefaultDescription
configObjectNoConfig Object
config.typeNumberNopipelineType of event: pipeline or pr
config.sortStringNodescendingOrder to sort by (ascending or descending)

Tokens

Get the pipeline's access tokens

model.tokens
    .then((tokens) => {
        // do stuff with tokens
    });

Get Event Metrics

Get all the event durations for this pipeline within time range

model.getMetrics()
    .then((metrics) => {
        // do stuff with metrics
    });

Job Factory

Search

'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
});
ParameterTypeDescription
configObjectConfiguration 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.pipelineIdNumberThe 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
idNumberThe unique ID for the job
config.pipelineIdNumberId of the pipeline the job is associated with
config.nameStringName of the job

Job Model

'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

Update a job

model.update()

Get builds

Return builds that belong to this job

model.getBuilds(config)
ParameterTypeRequiredDefaultDescription
configObjectNoConfiguration Object
config.sortStringNodescendingascending or descending

Get running builds

Return all running builds that belong to this jobId

model.getRunningBuilds()

Get Build Metrics

Get all the build durations for this job within time range

model.getMetrics()
    .then((metrics) => {
        // do stuff with metrics
    });

Build Factory

Search

'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
});
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.scmContextStringYesScm context to which user belongs
config.containerStringNoContainer for the build to run in
config.shaStringNoSHA used to kick off the build
config.prRefStringNoPR branch or reference; required for PR jobs
config.eventIdNumberNoId of the event this build belongs to

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
idNumberThe unique ID for the build
config.jobIdNumberThe unique ID for a job
config.numberNumberbuild number

Get Build Statuses

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
});
ParameterTypeRequiredDescription
configObjectYesConfiguration Object
config.jobIdsArrayYesIds of the jobs to get build statuses for
config.numBuildsNumberNoNumber of build statuses to return per job
config.offsetNumberNoNumber of build statuses to skip per job

Get Latest Builds

Get the latest builds for each job in corresponding groupEventId.

factory.getLatestBuilds(config).then(latestBuilds => {
    // do stuff with the latest builds
});
ParameterTypeRequiredDescription
configObjectYesConfiguration Object
config.groupEventIdNumberYesGroup event ID to get latest builds for

Build Model

'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

Update a specific build

model.update()

Stream

Stream the log of a build

model.stream()

Update commit status

Update a commit status

model.updateCommitStatus(pipeline)
ParameterTypeDescription
pipelinePipelineThe pipeline that this build belongs to

Start a build

Start the build and update commit status as pending

model.start()

Stop a build

model.stop()

Check if a build is done

model.isDone()

User Factory

Search

'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
});
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.scmContextStringYesScm context to which user belongs
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. 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
});
ParameterTypeDescription
idNumberThe unique ID for the build
config.usernameStringUser name
config.scmContextStringScm context to which user belongs
config.accessTokenStringA user access token value

User Model

'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

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(scmUri)
ParameterTypeDescription
scmUriStringThe scmUri of the repo

Tokens

Get the user's access tokens

model.tokens
    .then((tokens) => {
        // do stuff with tokens
    });

Secret Factory

Search

'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
});
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.pipelineIdNumberYesPipeline 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
idNumberThe unique ID for the build
config.pipelineIdNumberPipeline that the secret belongs to
config.nameStringSecret name

Secret Model

'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

Update a specific secret

model.update()

Event Factory

Search

'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
});
ParameterTypeDescription
configObjectConfig Object
config.paramsObjectfields to search on

Create

factory.create(config).then(model => {
    // do stuff with event model
});
ParameterTypeRequiredDescription
configObjectYesConfiguration Object
config.typeStringNoEvent type: pipeline or pr
config.pipelineIdNumberYesUnique identifier of pipeline
config.shaStringYesCommit sha that the event was based on
config.workflowGraphObjectNoWorkflow graph of the pipeline, with edges and nodes
config.usernameStringYesUsername of the user that creates this event
config.causeMessageStringNoMessage that describes why the event was created

Get

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
});
ParameterTypeDescription
idNumberThe unique ID for the build
config.pipelineIdNumberUnique identifier of pipeline
config.shaStringCommit sha that the event was based on

Event Model

'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

Update a specific event

model.update()

Get builds

Get builds that belong to this event

model.getBuilds()

Get Build Metrics

Get all the build durations for this event within time range

model.getMetrics()
    .then((metrics) => {
        // do stuff with metrics
    });

Template Model

'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: 'foo@bar.com',
    scmUri: 'github:123:master',
    config: { image: 'node:6'},
    labels: ['beta', 'stable']
}

factory.create(config)
    .then(model => {    // do something
    });

Update

Update a specific template

model.update()

Template Factory

Create

factory.create(config).then(model => {
    // do stuff with template model
});
ParameterTypeRequiredDescription
configObjectYesConfiguration Object
config.nameStringYesThe template name
config.namespaceStringNoThe template namespace
config.versionStringYesVersion of the template
config.descriptionStringYesDescription of the template
config.maintainerArrayYesMaintainer's email
config.configObjectYesConfig of the screwdriver-template.yaml
config.pipelineIdNumberYespipelineId of the template
config.labelsArrayNoLabels attached to the template

Get

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
});
ParameterTypeDescription
idNumberThe unique ID for the Template
config.namespaceStringTemplate namespace
config.nameStringTemplate name (can include namespace)
config.versionStringTemplate version

Get Template

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
});
ParameterTypeRequiredDescription
fullTemplateNameStringYesName of the template and the version or tag (e.g. chef/publish@1.2.3 or chef/publish@latest). Can also be just name of the template (e.g. chef/publish)

Search Template

'use strict';
const Model = require('screwdriver-models');
const factory = Model.TemplateFactory.getInstance({
    datastore
});
const config = {
    params: {
        name: 'chef/publish'
    },
    paginate {
        page: 1,
        count: 3
    }
}

factory.list(config).then(templates => {
    // Do stuff with list of templates
});
ParameterTypeDescription
configObjectConfig Object
config.paginate.pageNumberThe page for pagination
config.paginate.countNumberThe count for pagination
config.paramsObjectfields to search on

Template Tag Model

'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

Update a specific template tag

// update template version value
model.version = '2.4';

model.update();

Template Tag Factory

Create

factory.create(config).then(model => {
    // do stuff with template tag model
});
ParameterTypeRequiredDescription
configObjectYesConfiguration Object
config.nameStringYesThe template name
config.namespaceStringNoThe template namespace
config.tagStringYesThe template tag (e.g. stable, latest, etc)
config.versionStringYesVersion of the template

Get

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
});
ParameterTypeDescription
idNumberThe unique ID for the Template tag
config.namespaceStringTemplate namespace
config.nameStringTemplate name (can include namespace)

Search Template Tags

'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
});
ParameterTypeDescription
configObjectConfig Object
config.paginate.pageNumberThe page for pagination
config.paginate.countNumberThe count for pagination
config.paramsObjectfields to search on

Trigger Model

'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
});

Trigger Factory

Create

factory.create(config).then(model => {
    // do stuff with trigger model
});
ParameterTypeRequiredDescription
configObjectYesConfiguration Object
config.srcStringYesThe job that initiates the trigger (ex: ~sd@123:component)
config.destStringYesThe job that is triggered (ex: ~sd@456:main)

Get

Get trigger based on id.

factory.get(id).then(model => {
    // do stuff with trigger model
});
ParameterTypeDescription
idNumberThe unique ID for the trigger

List

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 destination(s) from source

Get destinations based on source trigger.

// update template version value
factory.getDestFromSrc('~sd@456:main').then(dests =>
    console.log(dests);
    // [destA, destB]
);
ParameterTypeDescription
srcStringThe job that initiates the trigger (ex: ~sd@123:component)

Get Triggers

Get triggers based on pipeline ID.

factory.getTriggers({ pipelineId, type }).then(result => {
    console.log(result);
    // [{
    //     jobName1,
    //     triggers: [destA, destB]
    // }, {
    //     jobName2,
    //     triggers: [destC, destD]
    // }]
});
ParameterTypeDescription
configObjectConfig object
config.pipelineIdNumberThe unique ID for the pipeline
config.typeStringType of jobs to get (pr or pipeline; default pipeline)

Token Factory

Search

'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
});
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 token model
});
ParameterTypeRequiredDescription
configObjectYesConfiguration Object
config.userIdNumberYesUser that this token belongs to
config.nameStringYesToken name
config.descriptionStringNoDescription of the token

Get

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
});
ParameterTypeDescription
idNumberThe unique ID for the token
config.valueStringThe value of the token

Token Model

'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

Update a specific token

model.update()

Refresh

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
    });

Collection Factory

Search

'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
});
ParameterTypeDescription
configObjectConfig object
config.paramsObjectFields to search on

Create

factory.create(config).then(model => {
    // do stuff with collection model
});
ParameterTypeRequiredDescription
configObjectYesConfiguration Object
config.userIdNumberYesUser that this collection belongs to
config.nameStringYesCollection name
config.descriptionStringNoCollection description
config.pipelineIdsArrayNoList of ids of pipelines associated with this collection

Get

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
})
ParameterTypeDescription
idNumberThe unique id for the collection

Collection Model

'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

Update a specific collection

model.update()

Remove

Remove a specific collection

model.remove()

Command Model

'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: 'foo@bar.com',
    format: 'habitat',
    habitat: {
        mode: 'remote',
        package: 'core/git/2.14.1',
        command: 'git'
    }
}

factory.create(config)
    .then(model => {    // do something
    });

Command Factory

Create

factory.create(config).then(model => {
    // do stuff with command model
});
ParameterTypeRequiredDescription
configObjectYesConfiguration Object
config.namespaceStringYesThe command namespace
config.nameStringYesThe command name
config.versionStringYesVersion of the command
config.descriptionStringYesDescription of the command
config.usageStringNoCommand usage and arguments (e.g.: 'sd-cmd exec foo/bar@1 -d -h ')
config.maintainerStringYesMaintainer's email
config.formatStringYesFormat of the command, habitat or docker or binary
config.habitatObjectYes (any one of habitat, docker, binary)Configuration Object for Habitat command
config.dockerObjectYes (any one of habitat, docker, binary)Configuration Object for Docker command
config.binaryObjectYes (any one of habitat, docker, binary)Configuration Object for Binary command

Get

Get a command based on id.

factory.get(id).then(model => {
    // do stuff with command model
});
ParameterTypeDescription
idNumberThe unique ID for the Command

Get 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
});
ParameterTypeRequiredDescription
fullCommandNameStringYesNamespace and name of the command and the version or tag (e.g. chefdk/knife@1.2.3 or chefdk/knife@latest). Can also be just namespace and name of the command (e.g. chefdk/knife)

Command Tag Model

'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

Update a specific command tag

// update command version value
model.version = '2.4.8';

model.update()

Command Tag Factory

Create

factory.create(config).then(model => {
    // do stuff with command tag model
});
ParameterTypeRequiredDescription
configObjectYesConfiguration Object
config.namespaceStringYesThe command namespace
config.nameStringYesThe command name
config.tagStringYesThe command tag (e.g. stable, latest, etc)
config.versionStringYesExact version of the command

Get

Get a command tag based on id.

factory.get(id).then(model => {
    // do stuff with command model
});
ParameterTypeDescription
idNumberThe unique ID for the Command Tag

Banner Factory

Search

'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
});
ParameterTypeDescription
configObjectConfig object
config.paramsObjectFields to search on

Create

factory.create(config).then(model => {
    // do stuff with banner model
});
ParameterTypeRequiredDefaultDescription
configObjectYesConfiguration Object
config.messageStringYesText of banner to be displayed
config.isActiveBooleanNofalseFlag for whether banner should display
config.typeStringNoinfoType/Severity of banner message. Options: info,warn
config.createdByStringYesUsername of the user creating the banner

Get

Get a banner based on unique id of banner.

factory.get(id).then(model => {
    // do stuff with banner model
});
ParameterTypeDescription
idNumberThe unique id for the banner

Banner Model

'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

Update a specific banner

model.update()

Remove

Remove a specific banner

model.remove()

BuildCluster Factory

Search

'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
});
ParameterTypeDescription
configObjectConfig object
config.paramsObjectFields to search on

Create

factory.create(config).then(model => {
    // do stuff with buildCluster model
});
ParameterTypeRequiredDefaultDescription
configObjectYesConfiguration Object
config.nameStringYesName of the build cluster (unique constraint)
config.descriptionStringNoDescription of the build cluster
config.scmContextStringYesSCM context
config.scmOrganizationsArrayYesSCM organizations that can use the build cluster
config.isActiveBooleanNofalseFlag for whether banner should display
config.managedByScrewdriverBooleanYesFlag for whether the cluster managed by Screwdriver
config.maintainerStringYesEmail of the maintainer
config.weightageStringNo100Weight percentage for build cluster (from 1 to 100)

Get

Get a buildcluster based on unique id of buildcluster.

factory.get(id).then(model => {
    // do stuff with buildcluster model
});
ParameterTypeDescription
idNumberThe unique id for the buildcluster

BuildCluster Model

'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: 'foo@bar.com'
};

factory.create(config)
    .then(model => {
        // do something with model
    });

Update

Update a specific BuildCluster

model.update()

Remove

Remove a specific BuildCluster

model.remove()

Testing


npm test

License

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

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free