Server jenkins building

Keywords: jenkins Java sudo yum

install

Judge java version

java -version


If it is the java version of GIJ, you need to reinstall java

sudo yum remove java
sudo yum install -y java-1.8.0-openjdk
sudo yum install -y git

To install jenkins:

sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
sudo yum -y install jenkins

You can modify / view the port number of jenkins through vim /etc/sysconfig/jenkins

So far jenkins installation is complete

If jenkins is not working properly, use systemctl status jenkins to check

Launch jenkins

systemctl start jenkins

Configuring environment variables for Jenkins

Open server console
input

echo $PATH

Copy the output.
On the jenkins page, open
Manage Jenkins > System Settings > Global Properties > environment variables > Add
Add PATH and paste the contents copied above.

Final preservation

Configure github private key for jenkins

Open jenkins web page
click

Click System

click


Click Add credentials

Select SSH Username with private key as the type
Fill in the name of the key for ID and description
Username is not required
Enter private key
Passphase is empty if not
Click OK

Finally, on github, configure public key

Configure pipeline

On the home page, click new assembly line
Then select the pipeline and click OK

General and trigger can be left blank, but pipeline script must be filled

Pipeline script case


node {
withEnv(["GOPATH=$WORKSPACE",'JENKINS_NODE_COOKIE=dontkillme']) {
   stage('Init gopath') {
       sh 'mkdir -p $WORKSPACE/react_app_src'
   }
   stage('Get code') {
       checkout([
           $class: 'GitSCM', 
           branches: [[name: '*/master']], 
           doGenerateSubmoduleConfigurations: false, 
           extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'react_app_src']], 
           submoduleCfg: [], 
           userRemoteConfigs: [[
               credentialsId: 'ssh_for_jenkins', 
               url: 'git@github.com:NikoKVCS/react_app.git'
           ]]
       ])
   }
   stage('Build go proejct') {      
       sh 'cd react_app_src;chmod +x ./build.sh;./build.sh'
   }
   stage('Run server') {      
       sh 'cd react_app_src;chmod +x ./deploy.sh;./deploy.sh'
   }
}
}

env.PROJ_DIR='src/go_react'

node {
withEnv(["GOPATH=$WORKSPACE"]) {
   stage('Init gopath') {
       sh 'mkdir -p $GOPATH/{bin,pkg,src}'
   }
   stage('Get code') {
       checkout([
           $class: 'GitSCM', 
           branches: [[name: '*/master']], 
           doGenerateSubmoduleConfigurations: false, 
           extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'src/go_react']], 
           submoduleCfg: [], 
           userRemoteConfigs: [[
               credentialsId: 'ssh_for_jenkins', 
               url: 'git@github.com:NikoKVCS/go_react.git'
           ]]
       ])
   }
   stage('Build go proejct') {      
       sh 'cd ${PROJ_DIR};chmod +x ./build.sh;./build.sh'
   }
   stage('Run server') {      
       sh 'cd ${PROJ_DIR};chmod +x ./deploy.sh;./deploy.sh'
   }
}
}

Posted by newbreed65 on Thu, 21 Nov 2019 11:45:26 -0800