Terraform Jenkins Pipeline用户输入失败



我正面临着一个问题与詹金斯Terraform管道,其中Terraform要求用户输入,我没有能力提供输入,结果构建失败。下面是我的配置:

Jenkinsfile:

pipeline {
agent any

stages {
stage ('Terraform Image version') {
agent{   
docker {
//args 'arg1'     // optional
label 'jenkins-mytask'
reuseNode true
alwaysPull true
registryUrl 'https://docker-xyz-virtual.artifactory.corp'
image 'docker-xyz-virtual.artifactory.corp/jenkins/slaves/terraform:0.12.15'
}
}
steps {
sh 'terraform --version'
sh 'ls -ltr'
sh 'terraform init -no-color'
sh 'terraform apply  -no-color'
}
}
}
}

Jenkins的错误输出:

Do you want to migrate all workspaces to "local"?
Both the existing "s3" backend and the newly configured "local" backend
support workspaces. When migrating between backends, Terraform will copy
all workspaces (with the same names). THIS WILL OVERWRITE any conflicting
states in the destination.

Terraform initialization doesn't currently migrate only select workspaces.
If you want to migrate a select number of workspaces, you must manually
pull and push those states.

If you answer "yes", Terraform will migrate all states. If you answer
"no", Terraform will abort.
Enter a value: 
Error: Migration aborted by user.

我需要了解是否有可能在Jenkins管道中处理这样的用户输入事件。

假设您确实想要迁移您的Terraform状态,那么您必须更新sh步骤方法中的标志,以便为这些提示提供非交互式输入:

sh 'terraform init -no-color -input=false -force-copy'

或者如果您不想迁移状态:

sh 'terraform init -no-color -input=false -reconfigure'

提醒下一个sh步骤方法也需要进行类似的修改:

sh 'terraform apply -no-color -input=false -auto-approve'

您可能还想在environment指令中设置正常环境变量:

environment { TF_IN_AUTOMATION = true }

最新更新