虛擬機器中 Jenkins 搭CI
Install Java8
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer
...
$ java -version
...
$ sudo apt-get install oracle-java8-set-default
$ vim ~/.bashrc
...
JAVA_HOME=/usr/lib/jvm/java-8-oracle
JRE_HOME=/usr/lib/jvm/java-8-oracle/jre
...
$ source ~/.bashrc
$ echo $JAVA_HOME
Install Git
$ sudo apt-get install git
$ git config --global user.name *******
$ git config --global user.email *****@thoughtworks.com
Add SSH Key
- $ ssh-keygen
- $ cat ~/.ssh/id_rsa.pub
- add SSH Key to GitHub
Jenkins
> mkdir jenkins
> cd jenkins
> wget http://mirrors.jenkins.io/war-stable/latest/jenkins.war
Update Vagrantfile
config.vm.network "forwarded_port", guest: 8080, host: 8080, host_ip: "127.0.0.1"
Get Password
java -jar jenkins.war --httpPort=8080
...
cat /home/vagrant/.jenkins/secrets/initialAdminPassword
Install Plugins
- suggested
- customized
Upload Jenkinsfile to GitHub
pipeline {
agent { docker 'maven:3.3.3' }
stages {
stage('build') {
steps {
sh 'mvn --version'
}
}
}
}
Jenkins
- New Item
- Multibranch Pipeline
- Add Source: GitHub
- Save
Build
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'echo "Hello World"'
sh '''
echo "Multiline shell steps works too"
ls -lah
'''
}
}
}
}
pipeline {
agent any
stages {
stage('Deploy') {
steps {
retry(3) {
sh './flakey-deploy.sh'
}
timeout(time: 3, unit: 'MINUTES') {
sh './health-check.sh'
}
}
}
}
}
need chmod 777 ./flakey-deploy.sh
or chmod +x ./flakey-deploy.sh
.
pipeline {
agent any
stages {
stage('Deploy') {
steps {
timeout(time: 3, unit: 'MINUTES') {
retry(5) {
sh './flakey-deploy.sh'
}
}
}
}
}
}
pipeline {
agent any
stages {
stage('Test') {
steps {
sh 'echo "Fail!"; exit 1'
}
}
}
post {
always {
echo 'This will always run'
}
success {
echo 'This will run only if successful'
}
failure {
echo 'This will run only if failed'
}
unstable {
echo 'This will run only if the run was marked as unstable'
}
changed {
echo 'This will run only if the state of the Pipeline has changed'
echo 'For example, if the Pipeline was previously failing but is now successful'
}
}
}
Environment Variables
before stages or in stage
environment {
DISABLE_AUTH = 'true'
...
TEST_CREDENTIAL_PWD = credentials('TEST_CREDENTIAL_ID')
TEST_CREDENTIAL_TEXT_ID = credentials('TEST_CREDENTIAL_TEXT_ID')
}
Jenkins -> Credentials -> Add Credential
Gradle
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew update && brew install gradle
$ gradle -v
build.gradle
apply plugin: 'idea'
//and standard one
apply plugin: 'java'
repositories {
jcenter()
mavenCentral()
}
task wrapper(type: Wrapper) {
gradleVersion = '4.2'
}
dependencies {
testCompile 'junit:junit:4.12' // for unit test
}
Gradle Wrapper
$ gradle wrapper
$ ./gradlew task
$ ./gradlew cleanIdea
$ ./gradlew idea
$ ./gradlew build
Change Jenkinsfile
build stage: ./gradlew build
test stage: ./gradlew check
Project Demo
感謝我的pair: 亞鑫
相關文章
- 通過Virtualbox搭載虛擬機器虛擬機
- Dalvik虛擬機器、Java虛擬機器與ART虛擬機器虛擬機Java
- Windows下搭載虛擬機器以及環境安裝Windows虛擬機
- java虛擬機器和Dalvik虛擬機器Java虛擬機
- Android 虛擬機器 Vs Java 虛擬機器Android虛擬機Java
- centos中安裝虛擬機器CentOS虛擬機
- 虛擬機器虛擬機
- 連線虛擬機器oracle 和虛擬機器KEY虛擬機Oracle
- 虛擬機器(三)虛擬機器配置靜態Ip虛擬機
- 在虛擬機器中安裝ftp虛擬機FTP
- vmware中ubuntu虛擬機器擴容Ubuntu虛擬機
- vmware虛擬機器網路中斷虛擬機
- 在vmare中建立centos虛擬機器CentOS虛擬機
- PD虛擬機器 18 for Mac(Mac虛擬機器軟體)虛擬機Mac
- JVM 虛擬機器JVM虛擬機
- JVM虛擬機器JVM虛擬機
- Neo 虛擬機器虛擬機
- VMware虛擬機器虛擬機
- 虛擬機器arm虛擬環境搭建虛擬機
- VMware虛擬機器如何設定使主機和虛擬機器不同IP虛擬機
- 深入理解虛擬機器之虛擬機器類載入機制虛擬機
- 如何在 Cockpit 中管理虛擬機器KPI虛擬機
- 在安卓虛擬機器中安裝apk安卓虛擬機APK
- 在虛擬機器CentOS中安裝docker虛擬機CentOSDocker
- 虛擬機器突然沒網了,虛擬機器突然滑鼠失靈虛擬機
- vmware克隆虛擬機器centos6.5,虛擬機器從新配置虛擬機CentOS
- 從ubuntu虛擬機器外部訪問虛擬機器內部資訊Ubuntu虛擬機
- 【虛擬機器】Windows(x86)上部署ARM虛擬機器(Ubuntu)虛擬機WindowsUbuntu
- xen安裝半虛擬化虛擬機器虛擬機
- 虛擬機器可以ping同宿主機,宿主機ping不通虛擬機器虛擬機
- JVM 虛擬機器 GCJVM虛擬機GC
- Java虛擬機器(JVM)Java虛擬機JVM
- 虛擬機器的概念虛擬機
- Python 虛擬機器Python虛擬機
- mac 裝虛擬機器Mac虛擬機
- 虛擬機器的克隆虛擬機
- kvm虛擬機器快照虛擬機
- 求助,虛擬機器崩了。。虛擬機