Jenkins: Difference between revisions

From NixOS Wiki
imported>Qknight
Created page with " [https://github.com/juspay/jenkins-nix-ci jenkins-nix-ci]: A NixOS module for Jenkins, optimized specifically for running projects using Nix. [https://github.com/mrVanDalo m..."
 
imported>Qknight
No edit summary
Line 1: Line 1:
== services.jenkins activation==
Write this into your /etc/nixos/configuration.nix
  services.jenkins = {
    enable = true;
  };
After a `nixos-rebuild switch`
Then the program is available via webbrowser at:
<http://localhost:8080>
=== CI configuration ===
Using the multibranch pipeline one can use this Jenkinsfile in the repository to build it:
  pipeline {
    agent any
    environment {
        PATH="/run/current-system/sw/bin"
    }
    stages {
        stage('Build') {
            steps {
                echo 'Building..'
                sh 'ls'
                sh 'nix-shell --command "just build"'
                archiveArtifacts artifacts: 'frontend/dist/*', fingerprint: true
            }
        }
        stage('Test') {
            steps {
                echo 'Testing..'
                sh 'nix-shell --command "just test"'
            }
        }
        stage('Check fmt') {
            steps {
                echo 'Checking fmt..'
                  sh 'nix-shell --command "cargo fmt --check"'
                  sh 'nix-shell --command "cd frontend; cargo fmt --check"'
            }
        }
    }
    post {
        changed {
            script {
                if (currentBuild.currentResult == 'FAILURE') {
                    emailext subject: '$DEFAULT_SUBJECT',
                        body: '$DEFAULT_CONTENT',
                        recipientProviders: [
                            [$class: 'CulpritsRecipientProvider'],
                            [$class: 'DevelopersRecipientProvider'],
                            [$class: 'RequesterRecipientProvider']
                        ],
                        replyTo: '$DEFAULT_REPLYTO',
                        to: '$DEFAULT_RECIPIENTS'
                }
            }
        }
        always {
            cleanWs(cleanWhenNotBuilt: false,
                    deleteDirs: true,
                    disableDeferredWipeout: true,
                    notFailBuild: true,
                    patterns: [[pattern: '.gitignore', type: 'INCLUDE'],
                              [pattern: '.propsfile', type: 'EXCLUDE']])
        }
    }
  }
== building nix projects ==


[https://github.com/juspay/jenkins-nix-ci jenkins-nix-ci]: A NixOS module for Jenkins, optimized specifically for running projects using Nix.
[https://github.com/juspay/jenkins-nix-ci jenkins-nix-ci]: A NixOS module for Jenkins, optimized specifically for running projects using Nix.


[https://github.com/mrVanDalo mrVanDalo] has a [https://git.ingolf-wagner.de/palo/nixos-config/src/branch/main/nixos/library/jenkins.nix library] to declare jenkins in his repository. It can be used as shown [https://git.ingolf-wagner.de/palo/nixos-config/src/branch/main/nixos/configs/workhorse/jenkins.nix here]
[https://github.com/mrVanDalo mrVanDalo] has a [https://git.ingolf-wagner.de/palo/nixos-config/src/branch/main/nixos/library/jenkins.nix library] to declare jenkins in his repository. It can be used as shown [https://git.ingolf-wagner.de/palo/nixos-config/src/branch/main/nixos/configs/workhorse/jenkins.nix here]

Revision as of 00:37, 12 January 2024

services.jenkins activation

Write this into your /etc/nixos/configuration.nix

 services.jenkins = {
   enable = true;
 };

After a `nixos-rebuild switch`

Then the program is available via webbrowser at:

<http://localhost:8080>

CI configuration

Using the multibranch pipeline one can use this Jenkinsfile in the repository to build it:

 pipeline {
   agent any
   environment {
       PATH="/run/current-system/sw/bin"
   }
   stages {
       stage('Build') {
           steps {
               echo 'Building..'
               sh 'ls'
               sh 'nix-shell --command "just build"'
               archiveArtifacts artifacts: 'frontend/dist/*', fingerprint: true
           }
       }
       stage('Test') {
           steps {
               echo 'Testing..'
               sh 'nix-shell --command "just test"'
           }
       }
       stage('Check fmt') {
           steps {
               echo 'Checking fmt..'
                 sh 'nix-shell --command "cargo fmt --check"'
                 sh 'nix-shell --command "cd frontend; cargo fmt --check"'
           }
       }
   }
   post {
        changed {
           script {
               if (currentBuild.currentResult == 'FAILURE') {
                   emailext subject: '$DEFAULT_SUBJECT',
                       body: '$DEFAULT_CONTENT',
                       recipientProviders: [
                           [$class: 'CulpritsRecipientProvider'],
                           [$class: 'DevelopersRecipientProvider'],
                           [$class: 'RequesterRecipientProvider']
                       ],
                       replyTo: '$DEFAULT_REPLYTO',
                       to: '$DEFAULT_RECIPIENTS'
               }
           }
       }
       always {
           cleanWs(cleanWhenNotBuilt: false,
                   deleteDirs: true,
                   disableDeferredWipeout: true,
                   notFailBuild: true,
                   patterns: [[pattern: '.gitignore', type: 'INCLUDE'],
                              [pattern: '.propsfile', type: 'EXCLUDE']])
       }
   }
 }

building nix projects

jenkins-nix-ci: A NixOS module for Jenkins, optimized specifically for running projects using Nix.

mrVanDalo has a library to declare jenkins in his repository. It can be used as shown here