Proper usage of Groovy Plug's 'system.build.start.date'?

Hello there,

I am somewhat lost here and maybe some one can help: I have the GroovyPlug plugin installed properly (at least it works perfectly fine for build read/write locks), but I want to use its 'system.build.start.date' in labels that are applied to the sources after a successful build. What exactly do I have to put in the 'Labeling pattern:' field under a config's VCS Settings tab in order to get labels in the format of 'abc-06-08-2010'?


Cheers and thanks,
-J

9 comments

Jörg,

With labeling pattern like "abc-%system.build.start.date%" you should be able to get the date into the label but in different format.
To change the format of system.build.start.date from 20100806 to 06-08-2010 you should probably change a line in file
.BuildServer\config\__groovyPlug__\GroovyPropertiesProvider.groovy
from
parameters.addEnvAndSystem("build.start.date", (new SimpleDateFormat("yyyyMMdd")).format(buildStartTime));
to
parameters.addEnvAndSystem("build.start.date", (new SimpleDateFormat("dd-MM-yyyy")).format(buildStartTime));
and run a new build to see how it works.

0

Hrm... I am using 'rfit%system.build.start.date%' in the Label pattern field but I get the following error after a successful build:


jetbrains.buildServer.ParametersResolvingFailedException:  Cannot resolve values for some of the specified references:  rfit%system.build.start.date% at  jetbrains.buildServer.vcs.impl.VcsLabeler.getLabelText(VcsLabeler.java:50) at  jetbrains.buildServer.vcs.impl.VcsLabeler.prepareLabel(VcsLabeler.java:15) at  jetbrains.buildServer.vcs.impl.VcsLabeler.access$200(VcsLabeler.java:12) at  jetbrains.buildServer.vcs.impl.VcsLabeler$3.buildFinished(VcsLabeler.java:8) at  sun.reflect.GeneratedMethodAccessor228.invoke(Unknown Source) at  sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  at java.lang.reflect.Method.invoke(Method.java:597) at  jetbrains.buildServer.util.EventDispatcher.dispatch(EventDispatcher.java:112) at  jetbrains.buildServer.serverSide.ServerSideEventDispatcher.access$000(ServerSideEventDispatcher.java:2)  at  jetbrains.buildServer.serverSide.ServerSideEventDispatcher$1$1.run(ServerSideEventDispatcher.java:1)  at  jetbrains.buildServer.serverSide.impl.auth.SecurityContextImpl$2.run(SecurityContextImpl.java:2)  at  jetbrains.buildServer.serverSide.impl.auth.SecurityContextImpl.runAs(SecurityContextImpl.java:0)  at  jetbrains.buildServer.serverSide.impl.auth.SecurityContextImpl.runAs(SecurityContextImpl.java:30)  at  jetbrains.buildServer.serverSide.impl.auth.SecurityContextImpl.runAsSystem(SecurityContextImpl.java:26)  at  jetbrains.buildServer.serverSide.ServerSideEventDispatcher$1.invoke(ServerSideEventDispatcher.java:1)  at $Proxy599.buildFinished(Unknown Source) at  jetbrains.buildServer.serverSide.impl.BuildServerImpl.finishBuild(BuildServerImpl.java:330)  at  jetbrains.buildServer.serverSide.impl.BuildServerImpl$6.run(BuildServerImpl.java:2)  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at  java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at  java.util.concurrent.FutureTask.run(FutureTask.java:138) at  java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  at  java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  at java.lang.Thread.run(Thread.java:619)
...
0

Jörg,

What TeamCity version do you use?
If you define a property with value "%system.build.start.date%", does it get correct value in the build (you will probably need to dump properties in the build to see the value)?

0

Yegor,

it's 5.1.3. Ok now I created system property and set the vcs settings to the ones below. Now a label named 'rfit' is appended (sans date in it) :\

ProjectConfig.png

VCSConfig.png

The 'GroovyPropertiesProvider.groovy' file looks like this now:

/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package jetbrains.buildserver.groovyPlug;


import com.intellij.openapi.diagnostic.Logger
import java.text.SimpleDateFormat
import jetbrains.buildServer.serverSide.SBuild
import jetbrains.buildServer.serverSide.SBuildType
import jetbrains.buildServer.serverSide.parameters.AbstractBuildParametersProvider
import jetbrains.buildServer.util.StringUtil
import jetbrains.buildServer.vcs.SVcsModification
import jetbrains.buildServer.vcs.SVcsRoot
import jetbrains.buildServer.vcs.VcsRootEntry
import org.jetbrains.annotations.NotNull
import org.jetbrains.annotations.Nullable

/**
 * @author Yegor.Yarko
 *         Date: 04.03.2009
 */
public class GroovyPropertiesProvider extends AbstractBuildParametersProvider {
  private static final Logger LOG = Logger.getInstance(GroovyPropertiesProvider.class.getName());

  DataUtil dataProvider;

  GroovyPropertiesProvider() {
    LOG.info("GroovyPropertiesProvider initialized.");
  }

  @NotNull
  @Override
  public Map getParameters(@NotNull final SBuild build, final boolean emulationMode) {
    LOG.debug("Processing build: " + build);
    final BuildParameters parameters = new BuildParameters();
    try {
      addBuildStartTime(parameters, build);
      addRunParameters(parameters, build);
      addTriggeredBy(parameters, build, emulationMode);
      addLastModificationsRevisions(parameters, build);
    } catch (Exception e) {
      LOG.error("Critical error occurred during parameters calculation", e);
    }
    LOG.debug("Finished processing build: " + build);
    return parameters.getParameters();
  }

  private void addRunParameters(@NotNull final BuildParameters parameters, @NotNull final SBuild build) {
    SBuildType buildType = build.getBuildType();
    if (buildType == null) return;

    for (Map.Entry runParameter: buildType.getRunParameters().entrySet()) {
      parameters.addConfiguration("runParam." + runParameter.getKey(), runParameter.getValue());
    }
  }

  void addBuildStartTime(@NotNull final BuildParameters parameters, SBuild build) {
    Date buildStartTime = build.getStartDate();
    parameters.addEnvAndSystem("build.start.date", (new SimpleDateFormat("dd-MM-yyyy")).format(buildStartTime));
    parameters.addEnvAndSystem("build.start.time", (new SimpleDateFormat("HHmmss")).format(buildStartTime));
  }

  void addTriggeredBy(@NotNull final BuildParameters parameters, SBuild build, final boolean emulationMode) {
    if (build.getTriggeredBy().getUser() != null) {
      parameters.addConfiguration("build.triggeredBy.username", build.getTriggeredBy().getUser().getUsername());
    }else if (emulationMode){
      parameters.addConfiguration("build.triggeredBy.username", "n/a");
    }
    parameters.addConfiguration("build.triggeredBy", build.getTriggeredBy().getAsString());
  }

  void addLastModificationsRevisions(@NotNull final BuildParameters parameters, SBuild build) {
    final Map rootVersions = dataProvider.getLastModificationsRevisions(build);

    for (VcsRootEntry rootEntry: build.getVcsRootEntries()){
      SVcsRoot root = (SVcsRoot)rootEntry.getVcsRoot()
      addModificationParams(parameters, root, rootVersions.get(root));
    }
    if (build.getVcsRootEntries().size() == 1) {
      if (rootVersions.size() == 1) {
        addModificationParams(parameters, null, rootVersions.entrySet().iterator().next().getValue());
      }else{
        addModificationParams(parameters, null, null);
      }
    }
  }

  private def addModificationParams(BuildParameters parameters, @Nullable SVcsRoot root, @Nullable SVcsModification modification) {
    String suffix = root == null ? "" : "." + StringUtil.replaceNonAlphaNumericChars(root.getName(), (char) '_');
    parameters.addEnvAndSystem("build.vcs.lastIncluded.revision" + suffix, getVersion(modification));
    parameters.addEnvAndSystem("build.vcs.lastIncluded.timestamp" + suffix, getDate(modification))
  }

  private @NotNull String getDate(@Nullable SVcsModification modification) {
    if (modification != null) {
      return (new SimpleDateFormat("yyyyMMdd'T'HHmmssZ")).format(modification.getVcsDate())
    }else{
      "";
    }
  }

  private @NotNull  String getVersion(@Nullable SVcsModification modification) {
    if (modification == null){
      return "";
    }
    String version = modification.getDisplayVersion()
    if (version == null) {
      version = modification.getVersion();
    }
    return version;
  }
}



So why is no date appended?

-J

0

Jörg,

> So why is no date appended?
Because you've created a property with the same name. I meant _value_, not _name_.

Please remove "build.start.date" property from the Parameters section of the build configuration web UI.
You can add "test" property then set it to %system.build.start.date% and check what the value is inside the build script.

0

Yegor,

ok I removed the old one and created a new one named 'BuildDate' (see below), used that in the VCS setting (see 2nd picture), but now when triggering a build i get the message saying 'Warning: No enabled compatible agents for this build configuration. Please register a build agent or tweak build configuration requirements.'?

-J

ProjectConfig_2.png

VCSConfig_2.png

0

Jörg,

You can see why the build configuration is considered not compatible on the Agent Requirements tab.

So far looks like an issue with groovyPlug plugin installation. Can you make sure you have the plugin unmodified by backuping/deleting .BuildServer\config\__groovyPlug__ directory and reinstalling the plugin from the most recent version?

0

Yegor,

I did, but still get the incompatible client error. Removed the __groovyPlug__ folder, replaced (even though it was the same version from april 16th 2010), restarted tomcat.. the folder was recreated, but I still get this:

2010-08-10_1142.png

-J

0

Jörg,

Cannot reproduce this so far.

You can try to add the lines:

  <category name="jetbrains.buildserver.groovyPlug">
    <priority value="DEBUG"/>
    <appender-ref ref="ROLL"/>
  </category>

into conf\teamcity-server-log4j.xml file and restart the server.

Then try to run unrelated build and look for logging like:
[2010-08-11 16:12:28,736]  DEBUG - ver.groovyPlug.BuildParameters - Adding system property 'build.start.date' with value =20100811

If you cannot figure out what is wrong, please attach the full logs.

0

Please sign in to leave a comment.