Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
Fix compatibility issue with Jenkins 2.110+
Browse files Browse the repository at this point in the history
  • Loading branch information
galmeida committed Mar 14, 2018
1 parent 5bbb1eb commit 63210e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class AWSCodePipelineSCM extends hudson.scm.SCM {

private Job job;
private final boolean clearWorkspace;
//keeping this to avoid "data stored in an older format" jenkins warning
private final String projectName;
private final String actionTypeCategory;
private final String actionTypeProvider;
Expand Down Expand Up @@ -134,7 +135,7 @@ public AWSCodePipelineSCM(
this.awsAccessKey = Validation.sanitize(awsAccessKey.trim());
this.awsSecretKey = Validation.sanitize(awsSecretKey.trim());
this.proxyHost = Validation.sanitize(proxyHost.trim());
this.projectName = Validation.sanitize(projectName.trim());
this.projectName = null;
actionTypeCategory = Validation.sanitize(category.trim());
actionTypeProvider = Validation.sanitize(provider.trim());
actionTypeVersion = Validation.sanitize(version.trim());
Expand Down Expand Up @@ -174,15 +175,17 @@ protected PollingResult compareRemoteRevisionWith(
.withProvider(actionTypeProvider)
.withVersion(actionTypeVersion);

final String projectName = Validation.sanitize(project.getName().trim());

LoggingHelper.log(listener, "Polling for jobs for action type id: ["
+ "Owner: %s, Category: %s, Provider: %s, Version: %s, ProjectName: %s]",
actionTypeId.getOwner(),
actionTypeId.getCategory(),
actionTypeId.getProvider(),
actionTypeId.getVersion(),
projectName);
project.getName());

return pollForJobs(actionTypeId, listener);
return pollForJobs(projectName, actionTypeId, listener);
}

@Override
Expand Down Expand Up @@ -239,8 +242,8 @@ public boolean checkout(
return true;
}

public PollingResult pollForJobs(final ActionTypeId actionType, final TaskListener taskListener) throws InterruptedException {
validate(taskListener);
public PollingResult pollForJobs(final String projectName, final ActionTypeId actionType, final TaskListener taskListener) throws InterruptedException {
validate(projectName, taskListener);

// Wait a bit before polling, so not all Jenkins jobs poll at the same time
final long jitter = (long) RANDOM.nextInt(55 * 1000);
Expand Down Expand Up @@ -316,7 +319,7 @@ public void initializeModel() {
CodePipelineStateService.setModel(model);
}

private void validate(final TaskListener listener) {
private void validate(final String projectName, final TaskListener listener) {
Validation.validatePlugin(
awsAccessKey,
awsSecretKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void setUp() throws IOException, InterruptedException {
@Test
public void returnsBuildNowWhenThereIsAJob() throws InterruptedException, IOException {
// when
assertEquals(PollingResult.BUILD_NOW, scm.pollForJobs(ACTION_TYPE, null));
assertEquals(PollingResult.BUILD_NOW, scm.pollForJobs(PROJECT_NAME, ACTION_TYPE, null));

// then
final String expectedMessage = String.format("[AWS CodePipeline Plugin] Received job with ID: %1$s", jobId);
Expand All @@ -190,7 +190,7 @@ public void returnsNoChangesWhenThereAreNoJobs() throws InterruptedException, IO
when(pollForJobsResult.getJobs()).thenReturn(new ArrayList<Job>());

// when
assertEquals(PollingResult.NO_CHANGES, scm.pollForJobs(ACTION_TYPE, null));
assertEquals(PollingResult.NO_CHANGES, scm.pollForJobs(PROJECT_NAME, ACTION_TYPE, null));

// then
assertContainsIgnoreCase("No jobs found.", outContent.toString());
Expand Down Expand Up @@ -225,7 +225,7 @@ public void setUp() throws IOException, InterruptedException {
@Test
public void acknowledgesJobAndDownloadsInputArtifacts() throws InterruptedException, IOException {
// given
assertEquals(PollingResult.BUILD_NOW, scm.pollForJobs(ACTION_TYPE, null));
assertEquals(PollingResult.BUILD_NOW, scm.pollForJobs(PROJECT_NAME, ACTION_TYPE, null));

// when
assertTrue(scm.checkout(null, null, workspacePath, null, null));
Expand All @@ -251,7 +251,7 @@ public void acknowledgesJobAndDownloadsInputArtifacts() throws InterruptedExcept
public void doesNotDownloadArtifactsWhenAcknowledgeJobDoesNotReturnInProgressJob() throws InterruptedException, IOException {
// given
when(acknowledgeJobResult.getStatus()).thenReturn("Created");
assertEquals(PollingResult.BUILD_NOW, scm.pollForJobs(ACTION_TYPE, null));
assertEquals(PollingResult.BUILD_NOW, scm.pollForJobs(PROJECT_NAME, ACTION_TYPE, null));

// when
try {
Expand All @@ -277,7 +277,7 @@ public void doesNotDownloadArtifactsWhenAcknowledgeJobThrowsInvalidNonceExceptio
// given
when(codePipelineClient.acknowledgeJob(any(AcknowledgeJobRequest.class)))
.thenThrow(new InvalidNonceException("job was already acknowledged"));
assertEquals(PollingResult.BUILD_NOW, scm.pollForJobs(ACTION_TYPE, null));
assertEquals(PollingResult.BUILD_NOW, scm.pollForJobs(PROJECT_NAME, ACTION_TYPE, null));

// when
try {
Expand Down

0 comments on commit 63210e9

Please sign in to comment.