Search code examples
rundeck

Notifications job date format


I need a hint: how to change date format on jobs notification? I can't figure it out. As far as I understand, is related to messages.properties file, which I can't find. I created i18n directory with messages.properties file, but I'm not sure what is the format of messages file content. (found on albundy83 comment)

Date dateS = Date.parse( "yyyy-MM-dd HH:mm:ss.SSS", execution.dateStarted.toString() )
String dateStartedIso8601 = dateS.format( "yyyy-MM-dd'T'HH:mm:ss.SSSZ" )

Date dateE = Date.parse( "yyyy-MM-dd HH:mm:ss.SSS", execution.dateEnded.toString() )
String dateEndedIso8601 = dateE.format( "yyyy-MM-dd'T'HH:mm:ss.SSSZ" )

I have installed Rundeck 3.2.2 using RPM on CentOS 8.

Regards, Adi


Solution

  • To use that custom format you need to create a groovy plugin, follow this. Basically you need to create a .groovy file and put it on $RDECK_BASE/libext (as any plugin).

    I did an basic example modifying this plugin and this. Take a look:

    import java.text.SimpleDateFormat 
    import java.util.Date
    import com.dtolabs.rundeck.plugins.notification.NotificationPlugin;
    
    rundeckPlugin(NotificationPlugin){
        onstart { 
            println("job start: data ${execution}")
            true
        }
    
        onfailure {
            println("failure: data ${execution}")
            true
        }
    
        onsuccess {
            Date dateS = Date.parse( "yyyy-MM-dd HH:mm:ss.SSS", execution.dateStarted.toString() )
            String customdate = dateS.format( "dd-MM-YYYY" )
    
            println("success: data ${customdate}")
            true
        }
    }
    

    Output (success job execution):

    success: data 18-02-2020