1. 创建jenkins的流水线

2. 创建artifactory的镜像仓库

3. 创建generic的仓库上传需要的 war包还有tar包.

4. 修改pipeline的 脚本

主要修改的地方. 修改war包的原始路径, 将路径修改为步骤3中定义的路径.

修改后未成形的脚本

#!/usr/bin/env groovy

node ('master') {
//Clone example project from GitHub repository
git url: 'https://github.com/jinanxiaolaohu/swampup.git', branch: 'master'
def rtServer = Artifactory.server SERVER_ID
def buildInfo = Artifactory.newBuildInfo()
def tagName
buildInfo.env.capture = true
//Fetch all depensencies from Artifactory
stage('Dependencies') {
dir('automation/docker-framework') {
try {
println "Gather Java and Tomcat" def downloadSpec = """{
"files": [
{
"pattern": "zhaobsh_generic/jdk-8-linux-x64.tar.gz",
"target": "jdk/jdk-8-linux-x64.tar.gz",
"flat":"true"
},
{
"pattern": "zhaobsh_generic/apache-tomcat-8.tar.gz",
"target": "tomcat/apache-tomcat-8.tar.gz",
"flat":"true"
}
]
}""" rtServer.download (downloadSpec, buildInfo)
if (fileExists('jdk/jdk-8-linux-x64.tar.gz') && fileExists('tomcat/apache-tomcat-8.tar.gz')) {
println "Downloaded dependencies"
} else {
println "Missing Dependencies either jdk or tomcat - see listing below:"
sh 'ls -d */*'
throw new FileNotFoundException("Missing Dependencies")
}
} catch (Exception e) {
println "Caught exception during resolution. Message ${e.message}"
throw e
}
}
}
//Build docker image named "docker-framework" with Java 8 and Tomcat
stage('Build') {
dir ('automation/docker-framework') {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: CREDENTIALS, usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
def rtDocker = Artifactory.docker server: rtServer
tagName = "${ARTDOCKER_REGISTRY}/docker-framework:${env.BUILD_NUMBER}"
docker.build(tagName)
echo tagName
sleep
rtDocker.push(tagName,REPO, buildInfo)
sleep
rtServer.publishBuildInfo buildInfo
}
}
}
//Test docker image
stage('Test') {
dir('automation/docker-framework/framework-test') { def gradleLatestPath = getLatestGradleWar().trim()
def gradleWarDownload = """{
"files": [
{
"pattern": "zhaobsh_generic/webservice-1.1.2.war",
"target": "war/webservice.war",
"flat": "true"
}
]
}"""
echo "Test"
sh 'rm -f war/*'
sh "mkdir -p war"
rtServer.download(gradleWarDownload)
updateDockerFile()
def tagDockerFramework = "${ARTDOCKER_REGISTRY}/docker-framework-test:${env.BUILD_NUMBER}"
docker.build(tagDockerFramework)
if (testFramework(tagDockerFramework)) {
println "Setting property and promotion"
updateProperty ("functional-test=pass")
sh "docker rmi ${tagName}"
} else {
updateProperty ("functional-test=fail; failed-test=page-not-loaded")
currentBuild.result = 'UNSTABLE'
sh "docker rmi ${tagName}"
return
}
}
}
//Scan build's Artifacts in Xray
stage('Xray Scan') {
if (XRAY_SCAN == "YES") {
def xrayConfig = [
'buildName' : env.JOB_NAME,
'buildNumber' : env.BUILD_NUMBER,
'failBuild' : false
]
def xrayResults = rtServer.xrayScan xrayConfig
echo xrayResults as String
} else {
println "No Xray scan performed. To enable set XRAY_SCAN = YES"
}
sleep
} //Promote image from local staging repositoy to production repository
stage ('Promote') {
dir ('automation/docker-framework') {
def promotionConfig = [
'buildName' : env.JOB_NAME,
'buildNumber' : env.BUILD_NUMBER,
'targetRepo' : PROMOTE_REPO,
'comment' : 'Framework test with latest version of application',
'sourceRepo' : SOURCE_REPO,
'status' : 'Released',
'includeDependencies': false,
'copy' : true
]
rtServer.promote promotionConfig
reTagLatest (SOURCE_REPO)
reTagLatest (PROMOTE_REPO)
}
}
} def getLatestGradleWar () {
def response = ''
def gradleLatestWarSrc = """items.find(
{
"repo":{"\$eq":"zhaobsh_generic"}, "name":{"\$match":"webservice-*.war"}
}
).sort({"\$desc" : ["created"]}).limit()"""
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: CREDENTIALS, usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
def curlString = "curl -s -u " + env.USERNAME + ":" + env.PASSWORD + " " + SERVER_URL
def gradleLatestStr = curlString + "/api/search/aql -X POST -H 'Content-Type: text/plain' -d '" + gradleLatestWarSrc + "' | python -c 'import sys, json; print json.load(sys.stdin)[\"results\"][0][\"path\"]'"
println "Curl String is " + gradleLatestStr
response = sh (script: gradleLatestStr, returnStdout: true)
}
println "Curl response: " + response
return response
} def updateDockerFile () {
def BUILD_NUMBER = env.BUILD_NUMBER
sh 'sed -i "s/docker-framework:latest/docker-framework:$BUILD_NUMBER/" Dockerfile'
} def reTagLatest (targetRepo) {
def BUILD_NUMBER = env.BUILD_NUMBER
sh 'sed -E "s/@/$BUILD_NUMBER/" retag.json > retag_out.json'
switch (targetRepo) {
case PROMOTE_REPO :
sh 'sed -E "s/TARGETREPO/${PROMOTE_REPO}/" retag_out.json > retaga_out.json'
break
case SOURCE_REPO :
sh 'sed -E "s/TARGETREPO/${SOURCE_REPO}/" retag_out.json > retaga_out.json'
break
}
sh 'cat retaga_out.json'
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: CREDENTIALS, usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
def curlString = "curl -u " + env.USERNAME + ":" + env.PASSWORD + " " + SERVER_URL
def regTagStr = curlString + "/api/docker/$targetRepo/v2/promote -X POST -H 'Content-Type: application/json' -T retaga_out.json"
println "Curl String is " + regTagStr
sh regTagStr
}
}
//test docker image by runnning container
def testFramework (tag) {
def result = true
docker.image(tag).withRun('-p 8181:8181') {c ->
sleep
def stdout = sh(script: 'curl "http://localhost:8181/swampup/"', returnStdout: true)
if (stdout.contains("Welcome Docker Lifecycle Training")) {
println "*** Passed Test: " + stdout
} else {
println "*** Failed Test: " + stdout
result = false
}
}
sh "docker rmi ${tag}"
return result
} def updateProperty (property) {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: CREDENTIALS, usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
def curlString = "curl -u " + env.USERNAME + ":" + env.PASSWORD + " " + "-X PUT " + SERVER_URL
def updatePropStr = curlString + "/api/storage/${SOURCE_REPO}/docker-framework/${env.BUILD_NUMBER}?properties=${property}"
println "Curl String is " + updatePropStr
sh updatePropStr
}
}

5. 修改参数. 增加相关的 流水线中的参数.

6. 修改docker daemon.json的内容 修改json的文件形式

{
"registry-mirrors": ["http://a7d80d83.m.daocloud.io"],
"insecure-registries":["127.0.0.1:8081","10.24.101.99:8081","CentOS75:8081"]
}

7. fork 例子中的github地址,并且进行修改

https://github.com/jinriyang/swampup
fock 到自己的
修改dockerfile的内容
https://github.com/jinanxiaolaohu/swampup/blob/master/automation/docker-framework/Dockerfile 修改后的内容
FROM ubuntu:latest MAINTAINER zhaobsh RUN /bin/bash -c cd ~; cd /home ; mkdir -p exec
ADD jdk/jdk--linux-x64.tar.gz /home/exec
RUN /bin/bash -c cd /home/exec; mv /home/exec/jdk* /home/exec/jdk8
ENV JAVA_HOME=/home/exec/jdk8
RUN sed "/securerandom.source=/{s/file:\/dev\/random/file:\/dev\/urandom/}" /home/exec/jdk8/jre/lib/security/java.security -i ADD tomcat/apache-tomcat-.tar.gz /home/exec
RUN /bin/bash -c cd /home/exec; mv /home/exec/apache-tomcat-.* /home/exec/tomcat
ADD tomcat/server.xml /home/exec/tomcat/conf
ENV CATALINA_HOME=/home/exec/tomcat
ENV TEST_ENV= CMD /bin/bash -c cd /home/exec; /home/exec/tomcat/bin/catalina.sh run

8. 进行build with parameters 进行处理.

根据错误信息 进行修改 修改过的主要地方有:

1. 镜像仓库要准确.

2. github中的代码需要修改 commit

3. 修改groovy中的脚本代码分支.  一般使用master即可.

4. stage 是 Test 时 可以将 下载 testpass的参数去掉 因为没有进行 单元测试.

5. /etc/docker/daemon.json 一定要配置对, 写镜像的名称的时候 不能加http 不加上如果也没有修改 增加insecure-registries 的话 就会出现http和https的错乱了.

6. 但是发现test的部分 总是出问题. 提示错误如图示  暂时未解决.

这个是个bug jenkins 暂未解决..暂时不搞了

Jfrog Artifactory jenkins 流水线使用docker的方式培训[暂未成功]的更多相关文章

  1. jfrog artifactory jenkins pipeline 集成

    1. 预备环境 artifactory ( 开源版本 ) maven jenkins jenkins artifactory plugin (在插件管理安装即可) 2. 配置artifactory  ...

  2. Jfrog Maven jenkins pipeline 流水线 培训 简单实验

    1. 公司购买了一套jfrog artifactory ,然后厂商组织了一次培训 本次简单记录一下 jenkins和jfrog 二进制仓库的简单连接使用 2. 前期环境准备. scp jdk的tar包 ...

  3. Jenkins Jfrog Artifactory 以及docker下的pipeline 容器编排实践

    1. 测试环境情况: Docker主机 10.24.101.99 JFrog Artifactory 主机 (admin password) jenkinx github原始地址:https://gi ...

  4. Jfrog Artifactory 创建docker 镜像仓库以及 push 镜像到 该仓库.

    1. 安装aitifactory 以及 启动 使用30天有效期激活 不在阐述. 2. 登录artifactory username:admin password:password 3. 创建 仓库 在 ...

  5. jenkins流水线部署springboot应用到k8s集群(k3s+jenkins+gitee+maven+docker)(1)

    前言:前面写过2篇文章,介绍jenkins通过slave节点部署构建并发布应用到虚拟机中,本篇介绍k8s(k3s)环境下,部署jenkins,通过流水线脚本方式构建发布应用到k8s(k3s)集群环境中 ...

  6. 使用Jenkins来构建Docker容器

    使用Jenkins来构建Docker容器(Ubuntu 14.04) 当开发更新了代码,提交到Gitlab上,然后由测试人员触发Jenkins,于是一个应用的新版本就被构建了.听起来貌似很简单,dua ...

  7. JFrog Artifactory CE c&&c++ 包管理工具

    JFrog Artifactory CE 支持conan 以及普通二进制c&&c++包管理 使用docker 进行环境的搭建测试 安装 docker run -d -p 8081:80 ...

  8. Jenkins流水线(pipeline)实战之:从部署到体验

    关于Jenkins流水线(pipeline) Jenkins 流水线 (pipeline) 是一套插件,让Jenkins可以实现持续交付管道的落地和实施. 关于blueocean Blue Ocean ...

  9. docker 发布方式尝试

    docker 发布方式尝试 目前有个小项目, 尝试用docker的方式来发布, 项目只有一个节点, 使用 kubenate 有点小题大做, 所以采用docker-compose来发布. 发布过程 GI ...

随机推荐

  1. Java中关于LockSupport的简单入门记录

    LockSupport的JDK的文档描述:Basic thread blocking primitives for creating locks and other synchronization c ...

  2. 转 spring配置文件

    spring配置文件   pom文件: <properties> <commons-lang.version>2.6</commons-lang.version> ...

  3. 【转】对random_state参数的理解

    转自:https://blog.csdn.net/az9996/article/details/86616668 在学习机器学习的过程中,常常遇到random_state这个参数,下面来简单叙述一下它 ...

  4. Omi框架学习之旅 - 获取DOM节点 及原理说明

    虽然绝大部分情况下,开发者不需要去查找获取DOM,但是还是有需要获取DOM的场景,所以Omi提供了方便获取DOM节点的方式. 这是官网的话,但是我一直都需要获取dom,对dom操作,所以omi提供的获 ...

  5. Java多线程编程模式实战指南(三):Two-phase Termination模式

    停止线程是一个目标简单而实现却不那么简单的任务.首先,Java没有提供直接的API用于停止线程.此外,停止线程时还有一些额外的细节需要考虑,如待停止的线程处于阻塞(等待锁)或者等待状态(等待其它线程) ...

  6. 【LeetCode232】 Implement Queue using Stacks★

    1.题目描述 2.思路 思路简单,这里用一个图来举例说明: 3.java代码 public class MyQueue { Stack<Integer> stack1=new Stack& ...

  7. (转)对一个deb包的解压、修改、重新打包全过程方法

    转自:https://blog.csdn.net/yygydjkthh/article/details/36695243 Reference: http://www.debian.org/doc/ma ...

  8. C# DllImport 相对路径无法找到dll

    原文:C# DllImport 相对路径无法找到dll 如题,近期在开发过程中,需要调用C++的库,一般来说,使用下面的方法即可正常调用: [DllImport("hci_sys.dll&q ...

  9. Luogu P2602 [ZJOI2010]数字计数

    这算是一道数位DP的入门题了吧虽然对于我来说还是有点烦 经典起手式不讲了吧,\(ans(a,b)\to ans(1,b)-ans(1,a-1)\) 我们首先预处理一个东西,用\(f_i\)表示有\(i ...

  10. [Oacle][Partition]Partition操作与 Index, Global Index 的关系

    [Oacle][Partition]Partition操作与 Index, Global Index 的关系: ■ Regarding the local index and the global i ...