Jfrog Artifactory jenkins 流水线使用docker的方式培训[暂未成功]
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的方式培训[暂未成功]的更多相关文章
- jfrog artifactory jenkins pipeline 集成
1. 预备环境 artifactory ( 开源版本 ) maven jenkins jenkins artifactory plugin (在插件管理安装即可) 2. 配置artifactory ...
- Jfrog Maven jenkins pipeline 流水线 培训 简单实验
1. 公司购买了一套jfrog artifactory ,然后厂商组织了一次培训 本次简单记录一下 jenkins和jfrog 二进制仓库的简单连接使用 2. 前期环境准备. scp jdk的tar包 ...
- Jenkins Jfrog Artifactory 以及docker下的pipeline 容器编排实践
1. 测试环境情况: Docker主机 10.24.101.99 JFrog Artifactory 主机 (admin password) jenkinx github原始地址:https://gi ...
- Jfrog Artifactory 创建docker 镜像仓库以及 push 镜像到 该仓库.
1. 安装aitifactory 以及 启动 使用30天有效期激活 不在阐述. 2. 登录artifactory username:admin password:password 3. 创建 仓库 在 ...
- jenkins流水线部署springboot应用到k8s集群(k3s+jenkins+gitee+maven+docker)(1)
前言:前面写过2篇文章,介绍jenkins通过slave节点部署构建并发布应用到虚拟机中,本篇介绍k8s(k3s)环境下,部署jenkins,通过流水线脚本方式构建发布应用到k8s(k3s)集群环境中 ...
- 使用Jenkins来构建Docker容器
使用Jenkins来构建Docker容器(Ubuntu 14.04) 当开发更新了代码,提交到Gitlab上,然后由测试人员触发Jenkins,于是一个应用的新版本就被构建了.听起来貌似很简单,dua ...
- JFrog Artifactory CE c&&c++ 包管理工具
JFrog Artifactory CE 支持conan 以及普通二进制c&&c++包管理 使用docker 进行环境的搭建测试 安装 docker run -d -p 8081:80 ...
- Jenkins流水线(pipeline)实战之:从部署到体验
关于Jenkins流水线(pipeline) Jenkins 流水线 (pipeline) 是一套插件,让Jenkins可以实现持续交付管道的落地和实施. 关于blueocean Blue Ocean ...
- docker 发布方式尝试
docker 发布方式尝试 目前有个小项目, 尝试用docker的方式来发布, 项目只有一个节点, 使用 kubenate 有点小题大做, 所以采用docker-compose来发布. 发布过程 GI ...
随机推荐
- Spark LR逻辑回归中RDD转DF中VectorUDT设置
System.setProperty("hadoop.home.dir", "C:\\hadoop-2.7.2"); val spark = SparkSess ...
- Spring Boot中Web应用的统一异常处理
我们在做Web应用的时候,请求处理过程中发生错误是非常常见的情况.Spring Boot提供了一个默认的映射:/error,当处理中抛出异常之后,会转到该请求中处理,并且该请求有一个全局的错误页面用来 ...
- day16 Python 函数嵌套函数和作用域
#函数的作用域只跟函数声明时定义的作用域有关,跟函数的调用位置无任何关系 name = 'alex' def foo(): name='linhaifeng' def bar(): #name='wu ...
- Cookie,Session的区别
1.Cookie 存储在用户本地上即客户端的数据,用来辨别用户的身份. 如果勾选了记住我则会在C盘中保存Cookie的信息,直至Cookie设置的有效期过期 注意: (1)记录用户访问次数 (2)不可 ...
- <<linux device driver,third edition>> Chapter 2: Building and Running Modules
Kernel Modules Versus Applications Kernel modules programming is similar to event driven programming ...
- Html5 手机端网页
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- [01] JSP的基本认识
1.什么是JSP JSP,全称JavaServer Pages,是由Sun Microsystems公司倡导和许多公司参与共同建立的一种使软件开发者可以响应客户端请求,而动态生成HTML.XML或其他 ...
- php RSA加密传输代码示例
涉及敏感数据的传输,双方最好约定使用加密解密.那RSA非对称加密就大有作为了. 服务端可以保留自己的私钥,发给客户端对应的公钥.这样就可以互相加解密了.php中rsa加解密实现: 首先要生成一对公钥私 ...
- 【Linux系统目录结构】
登录系统后,在当前命令窗口下输入 ls / 你会看到 以下是对这些目录的解释: /bin bin是Binary的缩写.这个目录存放着最经常使用的命令. /boot 这里存放的是启动Linux时使用的一 ...
- JVM调优——之CMS 常见参数解析
最近在学习使用CMS这个GC,这里记录下常用的参数. 1. UseCMSCompactAtFullCollection 与 CMSFullGCsBeforeCompaction 有一点需要注意的是:C ...