You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 12 Next »

Introduction

Continuous Integration / Continuous Delivery (CI/CD) is a supported method for JS7 - Rollout of Scheduling Objects.

  • The scenarios are described with the JS7 - Git Repository Interface.
  • CI/CD includes to perform the following steps
    • in a test environment
      • to store scheduling objects of a JOC Cockpit inventory to a local Git repository,
      • to commit and to push changes to the remote Git repository.
    • in a prod environment
      • to copy changes from the remote test Git repository to the local prod Git repository,
      • to push changes from the local prod Git repository to the remote prod Git repository,
      • to update the JOC Cockpit inventory from the local Git repository,
      • to release and to deploy scheduling objects to Controllers and Agents.

The following examples assume that a local Git repository is set up in the test and prod environments, see PowerShell CLI 2.0 - Set up local Git Repository.

Steps to perform for the TEST Environment

The below example assumes that 

  • a top-level folder Accounting is used in the JOC Cockpit inventory,
  • this folder is mapped to a sub-directory with the same name and spelling in the file system,
  • this folder is created when setting up the repository otherwise it will be created by JOC Cockpit the first time that objects should be stored to the repository.

Store Scheduling Objects to local Git Repository

The following cmdlets are used:

Example how to store changes to a local Git repository
Import-Module JS7
Connect-JS7 -Url http://root:root@test-host:4446 -Id Controller | Out-Null

# Cleanup local repository by removing existing objects
Remove-JS7RepositoryItem -Folder /Accounting

# Store scheduling objects of the given folder and exclude draft versions to be used
Set-JS7RepositoryItem -Folder /Accounting -Recursive -NoDraft

Explanation:

  • Line 2: A number of ways are offered how to connect to JOC Cockpit, see JS7 - How to connect to JOC Cockpit using the PowerShell Module.
  • Line 5: The Accounting top-level folder and any sub-folders are removed from the local repository, for details see Remove-JS7RepositoryItem. This step is not required, however, it can be useful for consistency if scheduling objects that have been removed or renamed in the JOC Cockpit inventory.
  • Line 8: The Accounting top-level folder and any sub-folders are added to the local repository, see Set-JS7RepositoryItem.

Commit and push Changes to remote Git Repository

The following OS and Git commands suggest a typical sequence of steps:

Example how to commit and push changes to a remote repository
# Find the repository sub-directory managed by JOC Cockpit
cd /var/sos-berlin.com/js7/joc/jetty_base/resources/joc/repositories/rollout/Accounting

# Commit and push changes to the remote Git repository
git add .
git commit -m "changes to accounting jobs for v12.3"
git push

Example for a CI/CD Pipeline Script

The below example

Download: Rollout-JS7FromTest.ps1

Example CI/CD pipeline script for test environment
# --- Parameterization ---

$url = 'http://root:root@localhost:4446'
$controllerId = 'Controller'

$folder = '/TestRepo/testMyFolder'
$directory = 'C:\ProgramData\sos-berlin.com\js7\joc\jetty_base\resources\joc\repositories\rollout\TestRepo'


# --- Connection ---

Import-Module JS7
Connect-JS7 -Url $url -Id $controllerId | Out-Null


# --- Step 1: Check status of releasable and deployable objects ---

$items = Get-JS7ReleasableItem -Folder $folder -NoReleased
if ( $items.count )
{
    Write-Warning "CI/CD pipeline stopped: unreleased objects found:"
    foreach( $item in $items )
    {
        Write-Warning "unreleased object: type=$($item.objectType), valid=$($item.valid), folder=$($item.folder), name=$($item.objectName)"
    }

    # optionally release items
    $items | Publish-JS7ReleasableItem
}

# $items = Get-JS7DeployableItem -Folder $folder -NoDeployed
if ( $items.count )
{
    Write-Warning "CI/CD pipeline stopped: undeployed objects found:"
    foreach( $item in $items )
    {
        Write-Warning "undeployed object: type=$($item.objectType), valid=$($item.valid), folder=$($item.folder), name=$($item.objectName)"
    }

    # optionally deploy items
    $items | Publish-JS7DeployableItem -ControllerId $controllerId
}


# --- Step 2: Cleanup repository and store scheduling objects to repository ---

# Cleanup local repository by removing existing objects
Remove-JS7RepositoryItem -Folder $folder
 
# Store scheduling objects of the given folder and exclude draft versions to be used
Set-JS7RepositoryItem -Folder $folder -Recursive -NoDraft


# --- Step 3: add objects, commit and push to remote repository

cd $directory

git add .
git commit -m "changes to accounting jobs for v12.3"
git push


# --- Connection ---

Disconnect-JS7



Steps to perform for the PROD Environment

Copy Changes from TEST to PROD Git Repository

There are a number of ways how to achieve this using Git commands:

Example how to pull changes to a local Git repository
# add the test repo as a remote repository 
git remote add oldrepo git@github.com:sos-berlin/js7-demo-inventory-rollout-test.git

# get the test repo commits
git remote update

# examine the whole tree
git log --all --oneline --graph --decorate

# copy/cherry-pick the commits from the test repo into your local prod repo
git cherry-pick <commit-hash>

# check local prod repo
git log

# push changes to remote prod repo
git push origin master

# remove the reference to the test repo
git remote remove oldrepo


Explanation:

  • Line 11: The <commit-hash> identifies commits performed when pushing scheduling objects to the test repository. This step can be performed repeatedly to cherry-pick a number of commits.

Pull Changes to local Git Repository

The following OS and Git commands are used:

Example how to pull changes to a local Git repository
# Find the repository sub-directory managed by JOC Cockpit
cd /var/sos-berlin.com/js7/joc/jetty_base/resources/joc/repositories/rollout/Accounting

# Pull changes
git pull

Update JOC Cockpit Inventory from local Git Repository, Release and Deploy to Controller

The following cmdlets are used:

Example how to store changes to a local Git repository
Import-Module JS7
Connect-JS7 -Url http://root:root@prod-host:4446 -Id Controller | Out-Null

# Update the JOC Cockpit inventory from the local repository of the given folder
Update-JS7FromRepositoryItem -Folder /Accounting

# Release scheduling objects of the given folder
Publish-JS7ReleasableItem -Folder /Accounting -Recursive -NoReleased

# Deploy scheduling objects from the given folder to the Controller
Publish-JS7DeployableItem -ControllerId Controller -Folder /Accounting -Recursive -NoDeployed

Explanation:

  • Line 5: The JOC Cockpit inventory is updated from the local repository. This translates to the fact that objects with the same name are overwritten and that new objects are added. Updated objects are put to a draft status in the JOC Cockpit inventory. Find details from Update-JS7FromRepositoryItem.
  • Line 8: Scheduling objects that are not deployed to a Controller such as schedules and calendars are released. Should such objects be included in the changes to the local repository then they are in a draft status and should be released. The -NoReleased parameter prevents scheduling objects in a non-draft status from being released, for example objects that are not stored in the local repository but that have previously been released. For details see Publish-JS7ReleasableItem.
  • Line 11: Scheduling objects are deployed to the given Controller. The -NoDeployed parameter prevents scheduling objects in a non-draft status from being deployed, for example objects that are not stored in the local repository but that have previously been deployed. For details see Publish-JS7DeployableItem.

Further Resources

The above OS commands, Git commands and PowerShell cmdlets can be executed from JS7 workflows for automation of a CI/CD pipeline.


  • No labels