0

I'm running 3 pipelines in jenkins (CI, CD, CDP) when I run the CI pipe the final stage is a trigger for activate the pipe CD (Continuous Deployment), this receive a parameter APP_VERSION from CI (Continuous Integration) PIPE and deploy an instance with packer and run SERVERSPEC TEST, but serverspec test failed.

enter image description here

but the demo-app is installed via salstack

Image 2

The strange is when I run the CD and pass the parameter APP_VERSION manually this WORK !!

this is the final stage for pipeline CI

stage "Trigger downstream"
    echo 'parametro'
    def versionApp = sh returnStdout: true, script:"echo \$(git rev-parse --short HEAD) "
    build job: "demo-pipeCD", parameters: [[$class: "StringParameterValue", name: "APP_VERSION", value: "${versionApp}"]], wait: false
}

I have passed to serverspec the sbin PATH and not work.

EDIT: I add the code the test.

enter code here

require 'spec_helper'

versionFile = open('/tmp/APP_VERSION')
appVersion = versionFile.read.chomp

describe package("demo-app-#{appVersion}") do
it { should be_installed }
end

Also, i add the job pipeline

#!groovy

node {

step([$class: 'WsCleanup'])

stage "Checkout Git repo"
checkout scm

stage "Checkout additional repos"
dir("pipeCD") {
  git "https://git-codecommit.us-east- 
 1.amazonaws.com/v1/repos/pipeCD"
}

stage "Run Packer"
sh "echo $APP_VERSION"
sh "\$(export PATH=/usr/bin:/root/bin:/usr/local/bin:/sbin)"
sh "/opt/packer validate -var=\"appVersion=$APP_VERSION\" -var- 
file=packer/demo-app_vars.json packer/demo-app.json"
sh "/opt/packer build -machine-readable - 
var=\"appVersion=$APP_VERSION\" -var-file=packer/demo-app_vars.json 
packer/demo-app.json | tee packer/packer.log"

REPEAT .. the parameter APP_VERSION in job pipe is rigth and the demo-app app is installed before the execute the test.

  • Your job is a parameterized job, so you have to provide `APP_VERSION` every single time, right? You `spectest` says that your package should be installed, but it seems that it is not. Can you confirm the package `demo-app-` gets deployed (installed) prior of running `spec`? Not sure what OS you have, you may introduce a shell to print the installed package. – azbarcea Oct 21 '19 at 12:44
  • The serverspec test code and the jenkins-pipeline code would likely both be helpful. – Matthew Schuchard Oct 21 '19 at 13:24
  • @Matt Schuchard There are more info, i will wait that you can help me :) – Sebastian Garcia Oct 21 '19 at 14:38
  • So I somehow just noticed the serverspec test is executed as part of the pipeline after the packer build of the template. Have you considered executing the serverspec test as the final provisioner of the packer template instead? This is not uncommon, and may be easier for you as you then are only concerned with the packer build in the pipeline. – Matthew Schuchard Oct 21 '19 at 14:52

0 Answers0