Unfinished implementation in SCM class for buildEnvVars method

65 views
Skip to first unread message

pallen

unread,
Feb 3, 2015, 10:41:07 AM2/3/15
to jenkin...@googlegroups.com
Hi Guys,

Just started to update the P4 SCM plugin moving AbstractBuild to Run and AbstractProject to Job.

Previously I added some environment variables by extending buildEnvVars(AbstractBuild<?, ?> build, Map<String, String> env), however when I looked at the new implementation in SCM it seems unfinished.

/**
 * Adds environmental variables for the builds to the given map.
 *
 * <p>
 * This can be used to propagate information from SCM to builds
 * (for example, SVN revision number.)
 *
 * <p>
 * This method is invoked whenever someone does {@link AbstractBuild#getEnvironment(TaskListener)}, which
 * can be before/after your checkout method is invoked. So if you are going to provide information about
 * check out (like SVN revision number that was checked out), be prepared for the possibility that the
 * check out hasn't happened yet.
 */

 
// TODO is an equivalent for Run needed?
 
public void buildEnvVars(AbstractBuild<?,?> build, Map<String, String> env) {
   
// default implementation is noop.
 
}


Should this method be abstract or at least updated to use Run?

Kind regards,

Paul


Paul Allen

unread,
Feb 3, 2015, 1:32:44 PM2/3/15
to jenkin...@googlegroups.com
Hi Guys,

Sorry if this is documented, but I have more questions...

- How do I get a job from a run? Previously AbstractBuild had a getProject() method.

- MatrixBuild/MatrixConfigurations don't seem to be updated?

- Notify/Publish seem to use AbstractBuild

- RunListener seems half way?

I'm using Jenkins 1.580.3. It seems this is only partially implemented and it doesn't seem clear where the changes start/end. Do I just cast back to AbstractBuild when I can't get any further?

Kind regards,
Paul
> --
> You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/8a23acc2-17b3-46af-8312-fc2df574acda%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--------------------------------------------------------------------------------
This email and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed. If
you have received this email in error please notify the system manager. Please
note that any views or opinions presented in this email are solely those of the
author and do not necessarily represent those of Perforce Software. Finally,
the recipient should check this email and any attachments for the presence of
viruses. Perforce Software accepts no liability for any damage caused by any
virus transmitted by this email.

Perforce Software UK Ltd is registered in England and Wales as company no.
3816019 at the following address: West Forest Gate, Wellington Road, Wokingham,
RG40 2AT, UK
--------------------------------------------------------------------------------

Jesse Glick

unread,
Feb 5, 2015, 11:04:30 AM2/5/15
to Jenkins Dev
On Tue, Feb 3, 2015 at 10:41 AM, pallen <pal...@perforce.com> wrote:
> Should this method be abstract or at least updated to use Run?

Perhaps, but it does not seem critical for basic SCM integration:

https://issues.jenkins-ci.org/browse/JENKINS-24141

The most important use case would be

https://issues.jenkins-ci.org/browse/JENKINS-26100

but I think this would be better handled via scm-api-plugin.

Jesse Glick

unread,
Feb 5, 2015, 11:11:53 AM2/5/15
to Jenkins Dev
On Tue, Feb 3, 2015 at 12:10 PM, Paul Allen <pal...@perforce.com> wrote:
> How do I get a job from a run? Previously AbstractBuild had a getProject() method.

Use getParent(). I will note this in

https://github.com/jenkinsci/workflow-plugin/edit/master/scm-step/README.md

> MatrixBuild/MatrixConfigurations don't seem to be updated?

Not sure what the question is here. BTW feel free to ping me directly
on #jenkins for exploratory questions.

> Notify/Publish seem to use AbstractBuild

Yes. If this aspect of SCM operation is optional, just ignore it. If
it is mandatory, you will have to rethink what you are doing and why.

> RunListener seems half way?

You mean setUpEnvironment? This idiom cannot be used by a workflow, it
does not make sense. If you are using this, you probably just need to
do things differently, but I cannot say more without knowing the use
case.

> Do I just cast back to AbstractBuild when I can't get any further?

When the code in question only makes sense for an
AbstractProject/Build, you can make it conditional on an instanceof
check. For example, calls to token-macro-plugin are pointless for
workflows.

Paul Allen

unread,
Feb 6, 2015, 9:27:37 AM2/6/15
to jenkin...@googlegroups.com
Hi Jesse,

Thanks for helping to fill in some of the blanks. Now I have implemented it, it makes more sense.

I have been following the Mercurial Plugin as an example. Not sure if there is anything specific I need to implement for the p4 plugin to support the Workflow: SCM Step, but I guess that will become apparent as I experiment.

Kind regards,
Paul
> --
> You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr019UiUCi1Madr9-Ez5DVKC%3D3nEVBtJpn2OM_yy%2B3m72g%40mail.gmail.com.

Jesse Glick

unread,
Feb 6, 2015, 10:08:46 AM2/6/15
to Jenkins Dev
On Fri, Feb 6, 2015 at 9:27 AM, Paul Allen <pal...@perforce.com> wrote:
> I have been following the Mercurial Plugin as an example.

Good, that is the most straightforward example, because I wrote it. :-)

> Not sure if there is anything specific I need to implement for the p4 plugin to support the Workflow: SCM Step

Just what is listed in

https://github.com/jenkinsci/workflow-plugin/blob/master/scm-step/README.md#supporting-workflow-from-an-scm-plugin

Paul Allen

unread,
Feb 6, 2015, 10:45:06 AM2/6/15
to jenkin...@googlegroups.com
How would I add support for 'p4:' syntax instead (like the 'git:' example) instead of the 'scm: [$class: 'PerforceScm']' syntax?
> --
> You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr2r5NeN%3D9aQ7GnHyHRr6E2QiE7aDxoEUyatkUVc-%2BXtGw%40mail.gmail.com.

Jesse Glick

unread,
Feb 6, 2015, 10:49:40 AM2/6/15
to Jenkins Dev
On Fri, Feb 6, 2015 at 10:44 AM, Paul Allen <pal...@perforce.com> wrote:
> How would I add support for 'p4:' syntax instead (like the 'git:' example) instead of the 'scm: [$class: 'PerforceScm']' syntax?

For that you would need to create a custom subclass of SCMStep, thus
adding at least an optional dependency on that Workflow plugin.

Paul Allen

unread,
Feb 6, 2015, 11:00:04 AM2/6/15
to jenkin...@googlegroups.com
Sorry to ask so many questions...

I'm getting the error:

Started by user anonymous

Running: Allocate node : Start
Running on Achilles in /home/pallen/jenkins_slave/workspace/Workflow1
Running: Allocate node : Body : Start
Running: General SCM
Running: Allocate node : Body : End
Running: Allocate node : End
Running: End of Workflow
ERROR: P4: Run not instance of AbstractBuild.

Finished: FAILURE


With the configuration snippet:

node {
checkout scm: [$class: 'PerforceScm', credential: 'c1a588d9-199d-42c7-8c19-194629caf707', populate: [$class: 'AutoCleanImpl', delete: true, modtime: false, pin: '', replace: true], workspace: [$class: 'StaticWorkspaceImpl', charset: 'none', name: '${JOB_NAME}']]
}


I'm sure I can debug it, but if you have seen the error before it would save me some time. Can't understand why AbstractBuild is popping up again?

Paul
> --
> You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr18YcegneMGXgSDieFXuQU1VQPd7Uhxo1a7BhPZc4yTMw%40mail.gmail.com.

Jesse Glick

unread,
Feb 6, 2015, 11:26:20 AM2/6/15
to Jenkins Dev
On Fri, Feb 6, 2015 at 10:59 AM, Paul Allen <pal...@perforce.com> wrote:
> ERROR: P4: Run not instance of AbstractBuild.

Sounds like an error coming from your own code.

Paul Allen

unread,
Feb 9, 2015, 5:55:48 AM2/9/15
to jenkin...@googlegroups.com
Fixed it... I do like the workflow plugin, very nice to setup.

I hope to release support soon, a bit more testing and might look to extend SCMStep as a later release.

Thanks again for the support.

Kind regards,
Paul
> --
> You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr36M0sUOsJpOKyzYLAoaJgAzPzurt%2Bvcj2uWYD2xRg43w%40mail.gmail.com.

Jesse Glick

unread,
Feb 18, 2015, 3:27:44 PM2/18/15
to Jenkins Dev
On Mon, Feb 9, 2015 at 5:55 AM, Paul Allen <pal...@perforce.com> wrote:
> Fixed it

Cool! AFAIK the first SCM conversion not done by myself. :-)
Reply all
Reply to author
Forward
0 new messages