cicdgen CLI

CICDGEN CLI

cicdgen is a command line interface that helps you with some CICD in a devonfw project. At this moment we can only generate files related to CICD in a project but we plan to add more functionality in a future.

Installation
$ npm i -g @devonfw/cicdgen
Usage
Global arguments
  • --version

    Prints the cicdgen version number
  • --help

    Shows the usage of the command
Commands
Generate.

This command wraps the usage of angular schematics CLI. With this we generate files in a easy way and also print a better help about usage.

Available schematics that generate the code:

Examples
  • Generate all CICD files related to a devon4j project

    $ cicdgen generate devon4j
  • Generate all CICD files related to a devon4ng project with docker deployment.

    $ cicdgen generate devon4ng --groupid com.devonfw --docker --registryurl docker-registry-devon.s2-eu.capgemini.com
  • Generate all CICD files related to a devon4node project with OpenShift deployment.

    $ cicdgen generate devon4ng --groupid com.devonfw --openshift --registryurl docker-registry-devon.s2-eu.capgemini.com --ocname default --ocn devonfw
cicdgen usage example

In this example we are going to show how to use cicdgen step by step in a devon4ng project.

  1. Install cicdgen

    cicdgen is already included in the devonfw distribution, but if you want to use it outside the devonfw console you can execute the following command:

    $ npm i -g cicdgen
  2. Generate a new devon4ng project using devonfw ide.

    Inside a devonfw ide distribution execute the command (devon ng create <app-name>):

    $ devon ng create devon4ng
  3. Execute cicdgen generate command

    As we want to send notifications to MS Teams, we need to create the connector first:

    • Go to a channel in teams and click at the connectors button. Then click at the jenkins configure button.

      teams 1

    • Put a name for the connector

      teams 2

    • Copy the name and the Webhook URL, we will use it later.

      teams 3

    With the values that we get in the previous steps, we will execute the cicdgen command inside the project folder. If you have any doubt you can use the help.

    help 1

    help 2

    $ cicdgen generate devon4ng --groupid com.devonfw --docker --dockerurl tpc://127.0.0.1:2376 `--registryurl docker-registry-devon.s2-eu.capgemini.com --teams --teamsname devon4ng --teamsurl https://outlook.office.com/webhook/...`

    cicdgen command

  4. Create a git repository and upload the code

    gitlab

    gitlab 2

    $ git remote add origin https://devon.s2-eu.capgemini.com/gitlab/darrodri/devon4ng.git
    $ git push -u origin master

    push code

    As you can see, no git init or git commit is required, cicdgen do it for you.

  5. Create a multibranch-pipeline in Jenkins

    new pipeline

    When you push the save button, it will download the repository and execute the pipeline defined in the Jenkinsfile. If you get any problem, check the environment variables defined in the Jenkinsfile. Here we show all variables related with Jenkins:

    • chrome

      chrome stable

    • sonarTool

      sonar tool

    • sonarEnv

      sonar env

    • repositoryId

      repository id

    • globalSettingsId

      global settings id

    • mavenInstallation

      maven installation

    • dockerTool

      docker global

  6. Add a webhook in GitLab

    In order to run the pipeline every time that you push code to GitLab, you need to configure a webhook in your repository.

    gitlab webhook

Now your project is ready to work following a CICD strategy.

The last thing to take into account is the branch naming. We prepare the pipeline in order to work following the git-flow strategy. So all stages of the pipeline will be executed for the branches: develop, release/*, master. For the branches: feature/*, hotfix/*, bugfix/* only the steps related to unit testing will be executed.

Last updated 2021-12-03 14:05:40 UTC