Skip to content

Instantly share code, notes, and snippets.

@signed8bit
Last active March 16, 2017 19:25
Show Gist options
  • Save signed8bit/9d8e0f343ffd33f2f3d03dbcaba2b9f3 to your computer and use it in GitHub Desktop.
Save signed8bit/9d8e0f343ffd33f2f3d03dbcaba2b9f3 to your computer and use it in GitHub Desktop.
DEVNET-1027 Setting up a Pipeline

Setting up a Pipeline

Commit Job

  • New Item -> Freestyle Project

    • Name: python-commit-job
  • General

    • Execute concurrent builds if necessary: Checked
  • Source Code Management

    • Git
      • Repository URL: ssh://[email protected]:29418/${GERRIT_PROJECT}
      • Credentials: jenkins
      • Advanced
      • Refspec: ${GERRIT_REFSPEC}
      • Branch: ${GERRIT_BRANCH}
      • Additional Behaviors:
        • Strategy for choosing what to build
        • Choosing strategy: Gerrit Trigger
        • Checkout to a sub-directory
        • Local directory for repo: ${GERRIT_PROJECT}
  • Build Environment

    • Delete workspace before build starts: Checked
  • Build

    • Add build step: Execute shell

    • Gist: https://gist.github.com/signed8bit

        #!/usr/bin/env bash
      
        set -e
      
        virtualenv .test_venv
        source .test_venv/bin/activate
      
        cd ${WORKSPACE}/${GERRIT_PROJECT}
      
        pip install -r requirements-dev.txt
      
        flake8 . > ${WORKSPACE}/flake8.log
        py.test --junit-xml=${WORKSPACE}/nosetests.xml > ${WORKSPACE}/pytest.log
      
  • Post-build Actions

    • Add post-build action: Archive the artifacts
    • Files to archive: *.xml, *.log

Release Job

  • New Item -> Copy from (python-commit-job)

    • Name: python-release-job
  • Build Environment

    • Inject passwords to the build as environment variables
      • Job passwords: Add
        • Name: DEVPI_PASSWORD
        • Password: devnet
  • Build

    • Edit build step: Execute shell

    • Gist: https://gist.github.com/signed8bit

        #!/usr/bin/env bash
      
        set -e
      
        virtualenv .publish_venv --system-site-packages
        source .publish_venv/bin/activate
      
        cd ${WORKSPACE}/${GERRIT_PROJECT}
      
        pip install devpi-client
        pip install -r requirements-dev.txt
      
        devpi use http://cicd-sandbox.local:3141
        devpi login devnet --password=${DEVPI_PASSWORD}
        devpi use -l
      
        if [ "${GERRIT_EVENT_TYPE}" == "change-merged" ]; then
            # Make sure we are not on the patchset refspec
            git checkout ${GERRIT_BRANCH}
            devpi use devnet/release
            devpi upload
        else
            devpi use devnet/development
            devpi upload --no-vcs
        fi
      
  • Post-build Actions

    • Remove "Archive the artifacts"

Pipeline Job

  • New Item -> MultiJob Project

    • Name: python-pipeline
  • General

    • Execute concurrent builds if necessary: Checked
  • Build Triggers

    • Gerrit event
      • Choose a server: cico-sandbox.local
      • Trigger on: Patchset Created
      • Trigger on: Change Merged
    • Gerrit Projects
      • Plain: useful-lib
      • Path: **
      • Plain useful-cli
      • Path **
  • Build Environment

    • Delete workspace before build starts: Checked
  • Build

    • Add build step: MultiJob Phase
      • Phase name: Commit Stage
      • Phase jobs: python-commit-job
      • Continuation condition to next phase: Successful
    • Add build step: MultiJob Phase
      • Phase name: Release Stage
      • Phase jobs: python-release-job
      • Continuation condition to next phase: Successful

Making a Change

Open a Terminal (Applications -> Favorites -> Terminal) and go to ~/Projects/useful-lib

    Projects/useful-lib/

Activate the needed virtual environment

    lib_venv

Open the "Atom" text editor

    atom ./

Edit the setup.py file by changing 1.0.1 to 1.0.2 and save the file

    version='1.0.2',

Commit your change to Git

    git commit -am "Updated to v1.0.2"

Submit your change for review

    git review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment