Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-18947

Unable to use environment variables within the list of notification targets in the jabber plugin

XMLWordPrintable

      I tried to set up a Jabber notification that will be sent to $BUILD_USER_ID (environment variable that is set by another plugin), so the user who started the build will be notified when it is done. However the environment variables in the list of notification recipients does not resolve environment variables, so it tried to sent to user named literally "$BUILD_USER_ID" on the jabber server (not the intended recipient...)

      It would be nice if environment variables would be resolved in the list of people to notify, to enable notification to recipient addresses calculated by some other plugin.

      Following quick hack does what I need to do, but it is not a clean solution, and because of the storage format (plugin stores notification targets internally not as a string from configuration, but as a list of validated jabber IDs) it will be hard to change this cleanly and correctly - since environment variable may or may not contain complete username and may or may not contain more space separated targets, it would probably be necessary to store the target settings as a literal string, converting it to resolved list at end of the build once all the env vars are known and available (and not at time when configuration is saved).

       
      --------------- src/main/java/hudson/plugins/im/IMPublisher.java ---------------
      index 6fb5065..2a49a63 100644
      @@ -582,6 +582,9 @@ public abstract class IMPublisher extends Notifier implements BuildStep, MatrixA
       		{
       		    try {
                               log(buildListener, "Sending notification to: " + target.toString());
      +                        target = getIMDescriptor().getIMMessageTargetConverter().fromString(
      +                                build.getEnvironment(buildListener).expand(target.toString()));
      +                        log(buildListener, "(expanded) Sending notification to: " + target.toString());
       		        sendNotification(msg, target, buildListener);
       		    } catch (final Throwable t) {
       		        log(buildListener, "There was an error sending notification to: " + target.toString() + "\n" + ExceptionHelper.dump(t));
      

            kutzi kutzi
            mpl Martin Peticek
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: