Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(travis): Should not fail stage if Travis properties are not returned #4112

Merged
merged 4 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ public class GetBuildPropertiesTask extends RetryableIgorTask<CIStageDefinition>
stageDefinition.getPropertyFile(),
stageDefinition.getMaster(),
stageDefinition.getJob());
if (properties.size() == 0) {
if (properties.isEmpty()) {
if (stageDefinition.getMaster().startsWith("travis-")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any chance for stageDefinition.getMaster() to be null here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is the name of the buildmaster. It needs to be defined and is fetched from igor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it was null an exception would have been thrown a few lines up as well.

return TaskResult.builder(ExecutionStatus.SUCCEEDED).build();
}
throw new ConfigurationException(
String.format(
"Expected properties file %s but it was either missing, empty or contained invalid syntax",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import spock.lang.Subject
class GetBuildPropertiesTaskSpec extends Specification {
def executionRepository = Mock(ExecutionRepository)
def artifactUtils = new ArtifactUtils(new ObjectMapper(), executionRepository, new ContextParameterProcessor())
def buildService = Stub(BuildService)
def buildService = Mock(BuildService)

def BUILD_NUMBER = 4
def MASTER = "builds"
Expand All @@ -55,7 +55,7 @@ class GetBuildPropertiesTaskSpec extends Specification {
def stage = new StageExecutionImpl(execution, "jenkins", [master: MASTER, job: JOB, buildNumber: 4, propertyFile: PROPERTY_FILE])

and:
buildService.getPropertyFile(BUILD_NUMBER, PROPERTY_FILE, MASTER, JOB) >> [val1: "one", val2: "two"]
1 * buildService.getPropertyFile(BUILD_NUMBER, PROPERTY_FILE, MASTER, JOB) >> [val1: "one", val2: "two"]

when:
TaskResult result = task.execute(stage)
Expand All @@ -70,7 +70,7 @@ class GetBuildPropertiesTaskSpec extends Specification {
def stage = new StageExecutionImpl(execution, "jenkins", [master: "builds", job: "orca", buildNumber: 4, propertyFile: PROPERTY_FILE])

and:
buildService.getPropertyFile(BUILD_NUMBER, PROPERTY_FILE, MASTER, JOB) >>
1 * buildService.getPropertyFile(BUILD_NUMBER, PROPERTY_FILE, MASTER, JOB) >>
[val1: "one", val2: [complex: true]]

when:
Expand All @@ -91,7 +91,7 @@ class GetBuildPropertiesTaskSpec extends Specification {
def bindTask = new BindProducedArtifactsTask()

and:
buildService.getPropertyFile(BUILD_NUMBER, PROPERTY_FILE, MASTER, JOB) >>
1 * buildService.getPropertyFile(BUILD_NUMBER, PROPERTY_FILE, MASTER, JOB) >>
[val1: "one", artifacts: [
[type: "docker/image",
reference: "gcr.io/project/my-image@sha256:28f82eba",
Expand Down Expand Up @@ -121,7 +121,7 @@ class GetBuildPropertiesTaskSpec extends Specification {
}

and:
buildService.getPropertyFile(BUILD_NUMBER, PROPERTY_FILE, MASTER, JOB) >>
1 * buildService.getPropertyFile(BUILD_NUMBER, PROPERTY_FILE, MASTER, JOB) >>
{ throw igorError }

when:
Expand All @@ -136,7 +136,7 @@ class GetBuildPropertiesTaskSpec extends Specification {
def stage = createStage(PROPERTY_FILE)

and:
buildService.getPropertyFile(BUILD_NUMBER, PROPERTY_FILE, MASTER, JOB) >> [:]
1 * buildService.getPropertyFile(BUILD_NUMBER, PROPERTY_FILE, MASTER, JOB) >> [:]

when:
task.execute(stage)
Expand All @@ -146,6 +146,20 @@ class GetBuildPropertiesTaskSpec extends Specification {
e.message == "Expected properties file $PROPERTY_FILE but it was either missing, empty or contained invalid syntax"
}

def "does not fail stage even if properties are not returned from travis and build passed"() {
given:
def stage = createStage(PROPERTY_FILE, "travis-$MASTER")

and:
1 * buildService.getPropertyFile(BUILD_NUMBER, PROPERTY_FILE, "travis-$MASTER", JOB) >> [:]

when:
TaskResult result = task.execute(stage)

then:
result.status == ExecutionStatus.SUCCEEDED
}

def "does not fetch properties if the property file is empty"() {
given:
def stage = createStage("")
Expand All @@ -168,9 +182,9 @@ class GetBuildPropertiesTaskSpec extends Specification {
0 * buildService.getPropertyFile(*_)
}

def createStage(String propertyFile) {
def createStage(String propertyFile, String ciMaster = MASTER) {
return new StageExecutionImpl(Stub(PipelineExecutionImpl), "jenkins", [
master: MASTER,
master: ciMaster,
job: JOB,
buildNumber: BUILD_NUMBER,
propertyFile: propertyFile
Expand Down