Skip to content

About

Helper scripts for building the official Ceph packages

Resources

Stars

45 stars

Watchers

79 watching

Forks

Latest commit

 

History

6,539 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ceph-build

A repository for Ceph (and Ceph-related projects) so that they can be automatically configured in Jenkins.

The current state of the repo is of transition from single scripts to a properly structured one with directories that represent each project.

The structure is strict and provides a convention to set the order of execution of build scripts.

Job configuration is done via the CLI app Jenkins Job Builder on the actual directory for its own job (the job has its definition and its build process automated).

The JJB configuration defines the rules needed to generate and update/create all other Jenkins Jobs in this repo as long as they define the config/definitions along with a valid YAML file.

This script should have all the rules and requirements for generating the Jenkins configurations needed from the YAML files to create/update the jenkins job.

Deprecation

Any script in the top level of this repo has been removed, and temporarily placed in the deprecated branch. If a job requires any of those it should be ported to follow the structure of the Jenkins Job Builder project, like all the current jobs in this repository.

The deprecated branch will be removed by the end of 2018.

Any jobs removed from this repo will be automatically deleted by JJB.

Enforcement

The rules and structure for the builds are strictly enforced. If the convention is not followed, the builds will not work.

Changing Jenkins jobs in Jenkins is strongly discouraged. Changing something in the Jenkins UI does not guarantee it will persist and will probably be overwritten.

By default, this is how a directory tree would look like for a build for a project called foo that uses every choice available:

foo
├── config
|   ├── config
|   └── definitions
|       └── foo.yml
├── setup
|   ├── setup
|   ├── post
|   └── pre
└── build
    ├── build
    ├── post
    └── pre

This structure consists of two directories with scripts and one for configuration. The scripts should be included in the foo.yml file in whatever order the job requires.

For example, this is how it could look in the builders section for its configuration:

builders:
  # Setup scripts
  - shell: !include-raw ../../setup/pre
  - shell: !include-raw ../../setup/setup
  - shell: !include-raw ../../setup/post
  # Build scripts
  - shell: !include-raw ../../build/pre
  - shell: !include-raw ../../build/build
  - shell: !include-raw ../../build/post

These scripts will be added to the Jenkins server so that they can be executed as part of a job.

Job Naming Conventions

Each Jenkins job has two names:

  1. The main name for a job. This is the name: parameter in YAML.
  2. The human-friendly "display name" for a job. This is the display-name: parameter in YAML.

For regular jobs, we name the Jenkins job after the git repository name. For example, the "ceph-deploy" package is at https://github.com/ceph/ceph-deploy, so the job name is "ceph-deploy".

For Pull Request jobs, we use a similar convention for both the internal job name and the human readable "display name". For example, if the git repository is "ceph-deploy", then we name the Jenkins job ceph-deploy-pull-requests. The display-name is set to ceph-deploy: Pull Requests. In other words, to determine a display-name for a job that handles pull requests, simply append : Pull Requests to the name value.

In other words, for building pull requests to ceph-deploy, the Jenkins job YAML will have the following settings:

Scripts

Scripts that may hang should be using the timeout command:

timeout 600 ./bad-script.sh

The above command will make the job expire after ten minutes (the argument is in seconds).

Pull Request Jobs

Pull request jobs are fired by the Generic Webhook Trigger (the GitHub Pull Request Builder plugin is disabled). The repository's webhook delivers pull_request and issue_comment events to https://jenkins.ceph.com/generic-webhook-trigger/invoke with a token held in a Jenkins secret-text credential, one per repository: ceph/ceph uses pr-check-trigger-token, which also feeds ceph-pr-pipeline-trigger. Every job for that repository names the credential in token-credential-id and filters the events it wants with regex-filter-expression; see ceph-dashboard-pull-requests for a job that builds on PR open/push and on a trigger phrase, and ceph-pull-requests-ppc64le for a phrase-only job.

The plugin injects no ghprb* variables and posts no statuses, so each job concatenates scripts/build_utils.sh and scripts/github_pr_webhook.sh in front of its build script. That preamble resolves the PR number (ghprbPullId for comments and manual builds, pr_number for pull_request events), authorizes the trigger the way ceph-pr-pipeline-trigger does (the commenter or PR author needs write access, or the PR carries the ci-approved label), exports ghprbActualCommit, ghprbTargetBranch and friends, and posts the commit status named by PR_STATUS_CONTEXT for the whole build. Set STATUS_PREFIX (e.g. test/) when running a copy of the job against a real PR so the real status context is left alone.

"Document" Jobs

Some jobs don't actually run code; they simply build a project's documentation and upload the docs to ceph.com. One example is the "teuthology-docs-build" job.

For these jobs, note that the destination directory must be created on the ceph.com web server before the rsync command will succeed.

Polling and GitHub

Jenkins can periodically poll Git repos on github.com for changes, but this is slow and inefficient. Instead of polling GitHub, it's best to use GitHub's web hooks instead.

See the "jenkins-job-builder" job as an example.

  1. Set up the triggers section:

    triggers:
      - github
    
  2. Visit the GitHub repository's "settings" page, eg https://github.com/ceph/ceph-build/settings/hooks, and add a new web hook.

    • The Payload URL should be https://jenkins.ceph.com/github-webhook/ (note the trailing slash)
    • The Content type should be application/x-www-form-urlencoded
    • Secret should be blank
    • Select Just send the push event.

Testing JJB changes by hand, before merging to main

Sometimes it's useful to test a JJB change by hand prior to merging a pull request.

Jenkins is locked down using Role-Based Access Control (RBAC), so regular users can no longer modify production jobs directly (e.g., running jenkins-jobs update against an existing job will fail with a permissions error). Instead, you create your own copy of the job to test with. The job definition includes an authorization block granting your user full rights to that copy only.

  1. Log in to the Jenkins Web UI with GitHub OAuth

  2. Click your User icon in the top right and go to Security

  3. Create an API key

  4. Install jenkins-job-builder on your local computer.

  5. Create $HOME/.jenkins_jobs.ini on your local computer:

    [jenkins]
    user=ktdreyer
    password=<your Jenkins API token>
    url=https://jenkins.ceph.com/
    

Where user is your Jenkins (ie GitHub) account username, and password is your Jenkins API token.

  1. Switch to the Git branch with the JJB changes that you wish to test:

    git checkout <branch with your changes>
    

Let's say this git branch makes a change in the my-cool-job job.

  1. Make a copy of the job definition to use for testing:

    cp my-cool-job/config/definitions/my-cool-job.yml \
       my-cool-job/config/definitions/preserve-my-cool-job-<yourusername>.yml
    
  2. Edit your copy and set the job name to match, using the preserve- prefix (e.g., preserve-my-cool-job-djgalloway). The preserve- prefix is important: it ensures your test job won't be deleted if the global jenkins-job-builder job runs — jobs named preserve-* are left alone.

    Then add an authorization property to the job. With inheritance-strategy: none, this matrix replaces the global RBAC for this job only, giving your user full rights to it without granting you access to any other jobs. Replace <your-username> with your Jenkins (GitHub) username:

    - job:
        name: preserve-my-cool-job-<your-username>
        properties:
          - authorization:
              inheritance-strategy: none
              USER:<your-username>:
                - job-read
                - job-discover
                - job-build
                - job-cancel
                - job-configure
                - job-delete
                - job-move
                - job-workspace
                - run-replay
                - run-update
                - run-delete
                - scm-tag
    
  3. Run JJB to test the syntax of your changes:

    jenkins-jobs --conf ~/.jenkins_jobs.ini test my-cool-job/config/definitions/preserve-my-cool-job-<yourusername>.yml
    

    If everything goes ok, this will cause JJB to output the XML of your job(s). If there is a problem, JJB will print an error/backtrace instead.

  4. Creating a new job requires job creation permissions in Jenkins. If you don't already have them, open a ticket asking to be added to the jenkins-create GitHub team: https://tracker.ceph.com/projects/ci/issues/new

  5. Run JJB to create your test job on Jenkins:

    jenkins-jobs --conf ~/.jenkins_jobs.ini update my-cool-job/config/definitions/preserve-my-cool-job-<yourusername>.yml
    

    Because the job doesn't exist yet, update will create it. Subsequent runs of the same command will update your test job in place, which the authorization block permits.

  6. Run a throwaway build of your test job, and verify that your change didn't break anything and does what you want it to do.

  7. When you're finished testing, delete your test job:

    jenkins-jobs --conf ~/.jenkins_jobs.ini delete preserve-my-cool-job-<yourusername>
    

    Your authorization block includes job-delete, so you can clean up after yourself.

  8. Open your pull request with the changes to the original job definition only. Do not commit your test copy or its authorization block to main.

Assigning a job to a different Jenkins Master

We found one Jenkins controller wasn't enough to handle all the jobs we were demanding of it. The CI now supports multiple Jenkins controllers. If you wish to run your job on a different Jenkins controller:

  1. Create a config/JENKINS_URL file in your job directory containing only the FQDN of the target Jenkins controller:

    # Example
    $ cat my-cool-job/config/JENKINS_URL
    jenkins.example.com
    

A note on inclusive language

Like many software projects, the Ceph project has undertaken the task of migrating to more inclusive language. In the Ceph CI,

master branches are now main

slave is now builder

When referring to the main Jenkins server, master is now controller

Remaining references (like the Jenkins ssh-slaves plugin) are hardcoded and could not be changed.

About

Helper scripts for building the official Ceph packages

Resources

Stars

45 stars

Watchers

79 watching

Forks

Releases

Packages

Used by

Contributors

Languages