jenkinsfile无法运行Terraform

时间:2019-05-03 00:44:21

标签: github jenkins-pipeline terraform

我想手动运行我的jenkinsfile,并且应该能够从github存储库中提取main.tf  https://github.com/choppyfish46/terraform.git

这是我所做的,我无法弄清楚哪里出了问题

1)在jenkins中创建一个新的管道项目 2)在管道选项卡上复制jenkinsfile 3)出现“立即构建”错误

控制台输出

Started by user my_user
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /Users/mano/.jenkins/workspace/so_terraform
[Pipeline] {
[Pipeline] withCredentials
Masking only exact matches of $SECRET_KEY or $ACCESS_KEY
[Pipeline] {
[Pipeline] tool
[Pipeline] tool
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Tool Install)
[Pipeline] tool
[Pipeline] envVarsForTool
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (TerraformInit)
[Pipeline] tool
[Pipeline] envVarsForTool
[Pipeline] withEnv
[Pipeline] {
[Pipeline] dir
Running in /Users/mano/.jenkins/workspace/so_terraform/jenkins-terraform-pipeline/ec2_pipeline
[Pipeline] {
[Pipeline] sh
+ terraform init -input=false
[0m[1mTerraform initialized in an empty directory![0m

The directory has no Terraform configuration files. You may begin working
with Terraform immediately by creating Terraform configuration files.[0m
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (TerraformFormat)
[Pipeline] tool
[Pipeline] envVarsForTool
[Pipeline] withEnv
[Pipeline] {
[Pipeline] dir
Running in /Users/mano/.jenkins/workspace/so_terraform/jenkins-terraform-pipeline/ec2_pipeline
[Pipeline] {
[Pipeline] sh
+ terraform fmt -list=true -write=false -diff=true -check=true
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (TerraformPlan)
[Pipeline] tool
[Pipeline] envVarsForTool
[Pipeline] withEnv
[Pipeline] {
[Pipeline] dir
Running in /Users/mano/.jenkins/workspace/so_terraform/jenkins-terraform-pipeline/ec2_pipeline
[Pipeline] {
[Pipeline] script
[Pipeline] {
[Pipeline] sh
+ terraform workspace new null
[0m[32m[1mCreated and switched to workspace "null"![0m[32m

You're now on a new, empty workspace. Workspaces isolate their state,
so if you run "terraform plan" Terraform will not see any existing state
for this configuration.[0m
[Pipeline] sh
+ terraform plan -var access_key=**** -var secret_key=**** -out terraform.tfplan
[31m
[1m[31mError: [0m[0m[1mNo configuration files found!

Plan requires configuration to be present. Planning without a configuration
would mark everything for destruction, which is normally not what is desired.
If you would like to destroy everything, please run plan with the "-destroy"
flag or create a single empty configuration file. Otherwise, please create
a Terraform configuration file in the path being executed and try again.[0m

[0m[0m[0m
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (TerraformApply)
Stage "TerraformApply" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE

1 个答案:

答案 0 :(得分:0)

从您的代码中,我不确定此目录来自何处

jenkins-terraform-pipeline/ec2_pipeline/

您是否再次尝试删除下面的部分?

 dir('jenkins-terraform-pipeline/ec2_pipeline/'){