Skip to content

Cr1t-GYM/Jenkinsfile-runner-actions-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Demo project for Jenkinsfile Runner Action for GitHub Actions in GSoC 2022

This is the demo project for the original POC project. It teaches the users how to use Jenkinsfile-runner Actions.

Demo

All the demos are stored in the ./demo directory. You can use them with jenkinsfile-runner-action, jfr-container-action and jfr-static-image-action.

  1. Java demo: It's a Spring Boot project. The source files are generated by Spring Initializr.
  2. JavaScript demo: It's a React project. You can generate it by using npm init react-app ./my-react-app in the command line.
  3. Scala demo: It's a Scala project. You can generate it by using sbt new scala/scalatest-example.g8 in the command line.
  4. Jenkins secrets demo: It teaches you how to define and use secrets in the Jenkins pipeline.
  5. Jenkins environment variables demo: It teaches you how to define and use environment variables in the Jenkins pipeline.
  6. s3-artifact-manager demo: It teaches you how to store the pipeline results to an external storage.
  7. jobcacher demo: It teaches you how to cache the pipeline dependencies.
  8. remote agent demo: It teaches you how to trigger the building in the remote agents.

How you can access Jenkinsfile-runner actions in your project?

Reference these actions in your workflow definition.

  1. Cr1t-GYM/jenkins-action-poc/jenkins-plugin-installation-action@master
  2. Cr1t-GYM/jenkins-action-poc/jenkinsfile-runner-action@master
  3. Cr1t-GYM/jenkins-action-poc/jenkins-setup@master
  4. Cr1t-GYM/jenkins-action-poc/jfr-container-action@master
  5. Cr1t-GYM/jenkins-action-poc/jfr-static-image-action@master

Step by step usage

  1. Prepare a Jenkinsfile in your repository. You can check the basic syntax of Jenkins pipeline definition.
  2. Prepare a workflow definition under the .github/workflows directory. You can check the official manual for more details.
  3. In your GitHub Action workflow definition, you need to follow these steps when calling other actions in sequence:
    1. Use a ubuntu runner for the job.
    jobs:
       job-name:
         runs-on: ubuntu-latest   
    1. If you use jfr-container-action, you need to declare using the ghcr.io/jenkinsci/jenkinsfile-runner:master or any image extended it. If you use jfr-static-image-action, you can skip this step.
    jobs:
       job-name:
         runs-on: ubuntu-latest
         container:
           image: ghcr.io/jenkinsci/jenkinsfile-runner:master             
    1. Call the actions/checkout@v2 to pull your codes into the runner.
    2. If you use jfr-container-action, you need to call Cr1t-GYM/jenkins-action-poc/jfr-container-action@master and give necessary inputs. If you use jfr-static-image-action, you need to call Cr1t-GYM/jenkins-action-poc/jfr-static-image-action@master and give necessary inputs. See the examples for these two actions.

Workflow Explanation

You can find the workflow definition in the .github/workflows/ci.yml.

jenkins-static-image-pipeline

This job pulls your repository first, and the workspace will be mapped to the container provided by jfr-static-image-action. By using the Cr1t-GYM/jenkins-action-poc/jfr-static-image-action@master and passing the necessary inputs, you can start the pipeline. Please note that most of the GitHub Actions will become invalid because of the isolation between the host machine and the container. You still can use actions/checkout@v2 to prepare your sources.

  jenkins-static-image-pipeline:
     runs-on: ubuntu-latest
     name: jenkins-static-image-pipeline-test
     steps:
        - uses: actions/checkout@v2
        # jfr-static-image-action
        - name: Jenkins pipeline with the static image
          id: jenkins_pipeline_image
          uses:
             Cr1t-GYM/jenkins-action-poc/jfr-static-image-action@master
          with:
             command: run
             jenkinsfile: Jenkinsfile
             pluginstxt: plugins.txt
             jcasc: jcasc.yml

jenkins-container-pipeline

This job pulls the ghcr.io/jenkinsci/jenkinsfile-runner:master, pulls your repository, setup maven and run the Jenkins pipeline finally. Please note that the declaration of ghcr.io/jenkinsci/jenkinsfile-runner:master is necessary to use the jfr-container-action action. By using the Cr1t-GYM/jenkins-action-poc/jfr-container-action@master and passing the necessary inputs, you can start the pipeline.

  jenkins-container-pipeline:
     runs-on: ubuntu-latest
     name: jenkins-prebuilt-container-test
     container:
        # prerequisite: extendance of ghcr.io/jenkinsci/jenkinsfile-runner:master
        image: path/to/your_own_image
     steps:
        - uses: actions/checkout@v2
        # jfr-container-action
        - name: Jenkins pipeline in the container
          id: jenkins_pipeline_container
          uses:
             Cr1t-GYM/jenkins-action-poc/jfr-container-action@master
          with:
             command: run
             jenkinsfile: Jenkinsfile
             pluginstxt: plugins.txt
             jcasc: jcasc.yml

jenkins-runtime-pipeline

This case is realized by the combination of jenkins-setup, jenkins-plugin-installation-action and jenkinsfile-runner-action. It will download all the dependencies and run the pipeline at the host machine directly. Its advantage is that it can support Linux, macOS and Windows runners. Its main disadvantage is the possibility of suffering from a plugins.jenkins.io outage.

  jenkins-runtime-pipeline:
     # Run all the actions in the on demand VM.
     needs: syntax-check
     strategy:
        matrix:
           os: [ubuntu-latest, macOS-latest, windows-latest]
     runs-on: ${{ matrix.os }}
     name: jenkins-runtime-pipeline-test
     steps:
        - uses: actions/checkout@v2
        - name : Setup Jenkins
          uses: Cr1t-GYM/jenkins-action-poc/jenkins-setup
        - name: Jenkins plugins download
          id: jenkins_plugins_download
          uses: Cr1t-GYM/jenkins-action-poc/jenkins-plugin-installation-action
          with:
             pluginstxt: jenkins-setup/plugins.txt
        - name: Run Jenkins pipeline
          id: run_jenkins_pipeline
          uses: Cr1t-GYM/jenkins-action-poc/jenkinsfile-runner-action
          with:
             command: run
             jenkinsfile: Jenkinsfile
             jcasc: jcasc.yml

About

Jenkinsfile Runner Action for GitHub Actions Test

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published