【发布时间】:2018-10-12 15:41:19
【问题描述】:
我有一个可以使用 terraform 自动部署一些基础设施的 jenkinsfile。不幸的是,在使用 git 源添加 terraform 模块后,它停止工作并出现以下错误:
+ terraform init -input=false -upgrade
Upgrading modules...
- module.logstash
Updating source "git::https://bitbucket.org/*****"
Error downloading modules: Error loading modules: error downloading 'https://bitbucket.org/*****': /usr/bin/git exited with 128: Cloning into '.terraform/modules/34024e811e7ce0e58ceae615c545a1f8'...
fatal: could not read Username for 'https://bitbucket.org': No such device or address
script returned exit code 1
上面的网址在事后被混淆了。以下是精简的模块语法:
module "logstash" {
source = "git::https://bitbucket.org/******"
...
}
以下是 Jenkins 文件:
pipeline {
agent {
label 'linux'
}
triggers {
pollSCM('*/5 * * * *')
}
stages {
stage ('init') {
steps {
sh 'terraform init -input=false -upgrade'
}
}
stage('validate') {
steps {
sh 'terraform validate -var-file="production.tfvars"'
}
}
stage('deploy') {
when {
branch 'master'
}
steps {
sh 'terraform apply -auto-approve -input=false -var-file=production.tfvars'
}
}
}
}
我认为这是 terraform 在内部使用 git 签出模块的问题,但 Jenkins 尚未在管道作业本身内配置 git 客户端。最好我能够以某种方式将多分支管道作业使用的凭据传递到作业本身并配置 git,但我不知道如何做到这一点。任何帮助,将不胜感激。
【问题讨论】:
-
是公共项目吗?
-
@ydaetskcoR 不,不幸的是。父项目和模块都是 bitbucket 中的私有仓库
-
这是一个 git 问题,而不是 Terraform/Jenkins 问题。
-
@MattSchuchard 我知道这是一个 git 凭据问题,但是它是从我遇到问题的 Jenkins 构建中传递结帐凭据的行为,而不是我可以配置的 git 本身手动操作。
-
我在你的管道代码中没有看到任何
withCredentials。
标签: jenkins jenkins-pipeline terraform