jenkins config

The installation

Installation environment: JDK, Jenkins, git (baidu)

After Jenkins installation is complete, install the recommended plug-in for novices, register the administrator account to enter the plug-in management, install NodeJS Plugin, Blue Ocean, Generic Webhook Trigger Plugin, restart Jenkins, You can restart the system by adding restart after jenkins_url

New project (assembly line)

  • Manage Jenkins-Global Tool Configuration- Add JDK path associated with server JDK – Add git path associated with server Git -NodeJS Select version, select automatic installation – Save and restart Jenkins

  • The pipeline does not support automatic installation of NodeJS, so node may not be found. You can create a free partition job, select Node to install, and configure node global variables on the server. The automatically installed Nodes are saved in the Tools of Jenkins_home, and then the pipeline is created

  • Enter /Dashboard/ Open Blue Ocean – Create pipeline, select the code repository (usually Git), fill in the repository address (HTTP is recommended), create credentials, create, return to /Dashboard

  • Item – Configuration – Branch source – Add-filter by name (with regular expression)- Enter the branch regular expression to be built

  • Git project adds Jenkinsfile to the root directory

    pipeline {
      agent {
        node {
            label 'master'
            // Specify jenkins_space note that Jenkinsfile paths should be split with /
            customWorkspace 'D:/Software1/huaiji/jenkins_space/roadManagementPC'}}// Configure Triggers for git webhooks to automatically trigger builds
      triggers {
        GenericTrigger (
          genericVariables: [[key: 'ref'.value: '$.ref']], // Extract the request parameters
          causeString: 'Triggered by $ref'.printContributedVariables: true.// Prints the extracted parameters
          printPostContent: true.silentResponse: false.token: 'dWEdB6KyOCwnPsaO'.// The webhook token is defined by itself
          regexpFilterText: '$ref'.// A value for build verification
          regexpFilterExpression: '^refs/heads/release$' // Build the checksum's re. When the checksum passes, the build is triggered)}/ / process
      stages {
        stage('INIT') {
          steps {
            bat ' ''// Windows CMD script node -v'' '}}}}Copy the code
  • Project – Branch -Build Now

  • Configure webhook in git repository project-settings-path format http://jenkins_url/generic-webhook-trigger/invoke? Token =Jenkinsfile configures the token option push to trigger webhook

  • Jenkins configuration is complete

Configure Jenkins role permissions

  • The installationRole-based Authorization StrategyThe plug-in
  • Manage Jenkins-Manage and Assign Roles-Manage Roles-Role to add
  • Create separateAdminG,AnonymousG,BuilderG,ViewerG– Administrator, other unauthorized users, Buildable (developers), read-only, and select permissions
  • Return -assign roles-user /group to add to add members and Assign Roles

Problems encountered in Jenkins configuration process and my solutions

  • Parametric construction

    • Parameterized build values are injected into script environment variables. Bat uses the % variable name %, node hangs on process.env, and so on in other environments
    • It is important to note that a Boolean value should be a string when determining whether an operation is performed based on the value of a variable in the Stages – stage-Steps-script'true','false'I was stuck for a while
    • Parameterized builds with default parameter values when triggers (such as Git push) are passed
  • Install package upload dandelion

    • The official recommended pluginUpload to pgyerIt is possible to create a separate free-style job for uploading, but it is too cumbersome
    • Curl curl curl curl curl curl curl curl curl curl
    • Unfortunately, Windows batch processing can’t handle multiple lines of text, so when the update instructions were multiple lines of text, each upload was parsed down to the first line, and I ended up running a segment through the pipelinenodeScript,requestSend a POST request to solve the multi-line text problem
  • Use the official pipelining syntax conversion tool

  • Docker is very fragrant