openshift - 使用带有 Openshift/jenkins-client-plugin 的 Pipeline 从 Dockerfile 构建映像
问题描述
我正在尝试将 OpenShift Jenkins 管道设置为:
- 从 git 获取源代码。源包括一个
Dockerfile
- 运行测试
- 使用 Dockerfile 构建镜像
- 将图像推送到 Imagestream
我创建了一个BuildConfig
withDocker
策略,它实际上可以在没有管道的情况下工作。问题是我不知道如何运行测试
如果我尝试从管道启动构建,它不会触发构建。
我在正确的道路上吗?对于这样的项目,最好的方法是什么?我应该继续依赖 OpenShift 特定工具吗?还是迁移到普通的 Kubernetes?
我正在为管道使用https://github.com/openshift/jenkins-client-plugin。
这是我的构建配置:
kind: "BuildConfig"
apiVersion: "v1"
metadata:
name: "front-end-build"
spec:
runPolicy: "Serial"
nodeSelector:
hostname: "vhkdld518"
source:
git:
uri: "https://kraporta@bitbucket/scm/~kraporta/test-kube.git"
strategy:
dockerStrategy:
from:
kind: "ImageStreamTag"
name: "nginx:alpine"
dockerfilePath: Dockerfile
output:
to:
kind: "ImageStreamTag"
name: "front-end:latest"
这是管道:
node {
stage('build') {
openshift.withCluster() {
openshift.withProject() {
echo "Using project: ${openshift.project()}"
def builds = openshift.selector("bc", "front-end-build").related('builds')
builds.describe()
timeout(5) {
builds.untilEach(1) {
it.describe()
echo "Inside loop: ${it}"
return (it.object().status.phase == "Complete")
}
}
}
}
}
}
非常感谢!
解决方案
我知道这是一个老问题,但我会保留它作为参考。
问题: 缺少步骤,您还没有开始构建过程,所以没有构建!
解决方案: 我们需要在获取构建之前开始构建过程,这里:
def builds = openshift.selector("bc", "front-end-build").related('builds')
成为(有很多方法可以完成):
def buildConfig = openshift.selector("bc", "front-end-build")
openshift.startBuild("front-end-build") # we started the build process
def builds = buildConfig.related('builds')
检查:https ://github.com/openshift/jenkins-client-plugin#watching-and-waiting-of-course
推荐阅读
- javascript - 使用带有 CSS 值的 js if/else
- ruby - 检查一个值是否等于数组中某个对象的属性值
- objective-c - 如何在目标c中的ios 10及以下版本中对表视图执行批量更新
- wordpress - 安装 W3 Total 缓存后,显示一些错误
- android - 在离子 1 中构建 android 时无法合并 Dex
- video - 使用 ffmpeg 在 beaglebone 上将原始视频转换为 mp4
- eclipse - 如何传输 adc stm32 蓝牙低功耗 x-nucleo 的值?
- c++ - 我们能否在层次结构中创建多个纯虚拟接口及其实现而不发生代码爆炸
- sql - 我需要帮助 - 让这个糟糕的查询变得更好
- gerrit - Gerrit 插件管理器不显示插件