cmdref.net - Cheat Sheet and Example

cmdref.net is command references/cheat sheets/examples for system engineers.

User Tools

Site Tools


Sidebar








Cloud



Etc


Reference














.

middleware:ci:jenkins:index.html



Middleware

Jenkins

About Jenkins


Jenkins Install

CentOS7

# wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
# rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key
# yum install jenkins
# systemctl start jenkins java


Jenkins Configuration

# cat /var/lib/jenkins/secrets/initialAdminPassword

http://x.x.x.x:8080/


How to write Pipeline

Sample1

node {
    stage 'Deploy1'
    sh "date"
    sh "whoami"
    sh "pwd"

    stage 'Deploy2'
    sh "sleep 3"
    sh "date"
}

ignore command errors

sh 'date | true'

Get script execution result

def RESULT = sh (
    script: "do something",
    returnStatus: true
) == 0

if(RESULT) {
  // do something
} else {
  // do something
}


TIPS

How to change execution user

Change Configuration

/etc/sysconfig/jenkins

JENKINS_USER="user01"
Change permissions for each directory and file
chown -R user01: /var/lib/jenkins /var/log/jenkins /var/cache/jenkins
restart Jenkins


How to export/import jobs

Export

Disable "CSRF"
Curl Command
curl -so config.xml --user USER:PASSWORD "http://x.x.x.x/config.xml"


Import

curl -XPOST --data-binary @config.xml --user USER:PASSWORD "http://x.x.x.x/config.xml"



Middleware




middleware/ci/jenkins/index.html.txt ยท Last modified: 2020/04/29 by admin

Page Tools