我正在尝试从SCM加载Jenkins管道脚本.我必须构建一个docker镜像并将其推送到GCR.在docker镜像中,我需要安装私有git存储库.在这里,我试图从Jenkins输入获取git用户名密码.但我不知道如何在Dockerfile中使用它来拉取git repo.这些是我在SCM中的Jenkinsfile和Dockerfile.有什么建议?
jenkins文件:
node {
def app
stage('Clone repository') {
checkout scm
def COMMITHASH = sh(returnStdout: true,script: "git log -n 1 --pretty=format:'%h'").trim()
echo ("Commit hash: "+COMMITHASH.substring(0,7))
}
stage('Build image') {
timeout(time: 600,unit: 'SECONDS') {
gitUser = input(
id: 'gitUser',message: 'Please enter git credentials :',parameters: [
[$class: 'TextParameterDefinition',defaultValue: "",description: 'Git user name',name: 'username'],[$class: 'PasswordParameterDefinition',description: 'Git password',name: 'password']
])
}
/* Build docker image */
println('Build image stage');
app = docker.build("testBuild")
}
stage('Push image') {
/* Push image to GCR */
docker.withRegistry('https://us.gcr.io','gcr:***') {
app.push("${env.BUILD_NUMBER}")
app.push("latest")
}
}
}
Dockerfile:
# use a ubuntu 16.04 base image
FROM ubuntu:16.04
MAINTAINER "someuser@company.com"
# Set environment variables
ENV DEBIAN_FRONTEND noninteractive
ENV LC_ALL C.UTF-8
# Upgrade the system
RUN apt-get update && apt-get -y upgrade && apt-get install -y python-software-properties software-properties-common
# Install cert bot and apache
RUN apt-get install -y apache2
#Enable apache modules
RUN a2enmod ssl
RUN a2enmod headers
RUN a2enmod rewrite
# Create directory for web application
RUN mkdir -p /var/www/myApp
# Expose ssl port
EXPOSE 443
我想在/ var / www / myApp中安装我的私有bitbucket存储库.另外,我想避免使用ssh身份验证.
最佳答案