Skip to content

Commit

Permalink
Merge pull request #5 from wolfgarnet/master
Browse files Browse the repository at this point in the history
Fix for issue JENKINS-13970
  • Loading branch information
wolfgarnet committed Jun 6, 2012
2 parents c3f8615 + 7fefb79 commit 75a3024
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 24 deletions.
43 changes: 43 additions & 0 deletions src/main/java/net/praqma/hudson/CCUCMRunListener.java
@@ -0,0 +1,43 @@
package net.praqma.hudson;

import net.praqma.hudson.scm.CCUCMScm;
import net.praqma.hudson.scm.CCUCMState.State;
import hudson.Extension;
import hudson.model.AbstractBuild;
import hudson.model.Run;
import hudson.model.listeners.RunListener;
import hudson.scm.SCM;

@Extension
public class CCUCMRunListener extends RunListener<Run> {

public CCUCMRunListener() {
super( Run.class );
}

@Override
public void onFinalized( Run r ) {
AbstractBuild<?, ?> build = null;
SCM scm = null;

if( r instanceof AbstractBuild ) {
try {
/* I don't even know if this works... */
build = (AbstractBuild<?, ?>)r;
scm = build.getProject().getScm();
} catch( Exception e ) {
System.out.println( "Ok, that didn't work..." );
return;
}

if( scm instanceof CCUCMScm ) {
String jobName = build.getParent().getDisplayName().replace( ' ', '_' );
int jobNumber = build.getNumber();
State state = CCUCMScm.ccucm.getState( jobName, jobNumber );

state.remove();
}
}
}

}
52 changes: 28 additions & 24 deletions src/main/java/net/praqma/hudson/scm/CCUCMScm.java
Expand Up @@ -769,40 +769,44 @@ public ChangeLogParser createChangeLogParser() {
public void buildEnvVars( AbstractBuild<?, ?> build, Map<String, String> env ) {
super.buildEnvVars( build, env );

System.out.println( "Th1s is(ENV) " + this );

if( CC_BASELINE == null ) {
try {
State state = ccucm.getState( jobName, jobNumber );

/* Baseline */
if( state.getBaseline() != null ) {
CC_BASELINE = state.getBaseline().getFullyQualifiedName();
} else {
CC_BASELINE = "";
}
} catch( Exception e ) {
System.out.println( "Variables not available: " + e.getMessage() );

/* Try env vars */
CCUCMBuildAction action = build.getAction( CCUCMBuildAction.class );
CC_BASELINE = action.getBaseline().getFullyQualifiedName();
} catch( Exception e1 ) {
System.out.println( "Failed to get baseline: " + e1.getMessage() );
try {
System.out.println( "Trying with env vars" );
String VAR_JOBNAME = env.get( "JOB_NAME" );
String n = env.get( "BUILD_NUMBER" );
int VAR_BUILDNUMBER = Integer.parseInt( n );

System.out.println( "VARS: " + VAR_JOBNAME + ", " + VAR_BUILDNUMBER );

State state = ccucm.getState( VAR_JOBNAME, VAR_BUILDNUMBER );
State state = ccucm.getState( jobName, jobNumber );

/* Baseline */
if( state.getBaseline() != null ) {
CC_BASELINE = state.getBaseline().getFullyQualifiedName();
} else {
CC_BASELINE = "";
}
} catch( Exception e1 ) {
System.out.println( "Not possible to retrieve variables: " + e1.getMessage() );
} catch( Exception e2 ) {
System.out.println( "Variables not available: " + e2.getMessage() );

/* Try env vars */
try {
System.out.println( "Trying with env vars" );
String VAR_JOBNAME = env.get( "JOB_NAME" );
String n = env.get( "BUILD_NUMBER" );
int VAR_BUILDNUMBER = Integer.parseInt( n );

System.out.println( "VARS: " + VAR_JOBNAME + ", " + VAR_BUILDNUMBER );

State state = ccucm.getState( VAR_JOBNAME, VAR_BUILDNUMBER );

/* Baseline */
if( state.getBaseline() != null ) {
CC_BASELINE = state.getBaseline().getFullyQualifiedName();
} else {
CC_BASELINE = "";
}
} catch( Exception e3 ) {
System.out.println( "Not possible to retrieve variables: " + e3.getMessage() );
}
}
}

Expand Down

0 comments on commit 75a3024

Please sign in to comment.