developer
June 3, 2020
Share

Local build

Screwdriver.cd offers powerful features such as templates, commandssecrets, and metadata, which can be used to simplify build settings or as build parameters. However, it’s difficult to reproduce equivalent features for local builds.

Although you can use these features by uploading your changes to an SCM such as GitHub, you may feel like it is a pain to upload your changes over and over in order to get a successful build. With sd-local, you can easily make sure the build is not corrupted before uploading changes to SCM and debug the build locally if it fails.

Note:
Because sd-local works with Screwdriver.cd, it does not work by itself. If you don’t have a Screwdriver.cd cluster, you need to set up it first.

See the documentation at https://docs.screwdriver.cd/cluster-management/.

How to Install

sd-local uses Docker internally, so make sure you have Docker Engine installed locally.

https://www.docker.com/

The next step is to install sd-local. Download the latest version of sd-local from the GitHub release page below and grant execute permission to it.

https://github.com/screwdriver-cd/sd-local/releases

$ mv sd-local_*_amd64 /usr/local/bin/sd-local$ chmod +x /usr/local/bin/sd-local

Build configuration

Configure to use the templates and commands registered in your Screwdriver.cd cluster from sd-local. sd-local communicates with the following SD components:

  • API
    • Validating screwdriver.yaml
    • Getting a template
  • Store
    • Getting a command
$ sd-local config set api-url https:// # e.g. https://api.screwdriver.cd
$ sd-local config set store-url https:// # e.g. https://store.screwdriver.cd

Set the API token for the above component to authenticate. Please refer the guide how to get an API token.

$ sd-local config set token 

Execute build

Please create the following screwdriver.yaml in the current directory.

jobs:
  main:
    image: node:12
    steps:
    - hello: echo -n "Hello, world!"

Run the build with the following command specifying the job name. Note: Builds can only be run at a job level.

$ sd-local build main
INFO   [0000] Prepare to start build...
INFO   [0017] Pulling docker image from node:12...
sd-setup-launcher: Screwdriver Launcher information
sd-setup-launcher: Version:        v6.0.70
sd-setup-launcher: Pipeline:       #0
sd-setup-launcher: Job:            main
sd-setup-launcher: Build:          #0
sd-setup-launcher: Workspace Dir:  /sd/workspace
sd-setup-launcher: Checkout Dir:     /sd/workspace/src/screwdriver.cd/sd-local/local-build
sd-setup-launcher: Source Dir:     /sd/workspace/src/screwdriver.cd/sd-local/local-build
sd-setup-launcher: Artifacts Dir:  /sd/workspace/artifacts
sd-setup-launcher: set -e && export PATH=$PATH:/opt/sd && finish() { EXITCODE=$?; tmpfile=/tmp/env_tmp; exportfile=/tmp/env_export; export -p | grep -vi "PS1=" > $tmpfile && mv $tmpfile $exportfile; echo $SD_STEP_ID $EXITCODE; } && trap finish EXIT;
sd-setup-launcher: echo ;
hello: $ echo -n Hello, world!
hello:
hello: Hello, world!

See the User Guide for more details about the commands.

Design Document

For more details, check out our design spec.

Compatibility List

In order to use this feature, you will need these minimum versions:

  • sd-local - v1.0.1
  • launcher - v6.0.70

Contributors

Thanks to the following contributors for making this feature possible:

Questions and Suggestions

We’d love to hear from you. If you have any questions, please feel free to reach out here. You can also visit us on Github and Slack.