Re: New plugin developer: A View Plugin

2018-04-20 Thread Sverre Moe
.


torsdag 19. april 2018 00.52.15 UTC+2 skrev Jesse Glick følgende:
>
> On Wed, Apr 18, 2018 at 5:18 PM, Sverre Moe <sverr...@gmail.com 
> > wrote: 
> > What kind of test is this? There is nothing in my newly created project. 
>
> The Jenkins plugin build harness generates a synthetic test to verify 
> basic sanity aspects of your plugin. I am not sure what specifically 
> the `FailingHttpStatusCodeException` is—that would be included in test 
> details under `target/surefire-reports/`. 
>

-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/43a5cdb7-47db-42e9-9520-ac47b2abbab2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


New plugin developer: A View Plugin

2018-04-18 Thread Sverre Moe
Let me begin starting with I have never written a plugin to Jenkins before.
I have plenty of insight into the Jenkins API for Groovy scripting in 
script console and scripting Pipeline scripts.
I am a Java developer for over 10 years (API/Spring, Swing/JavaFX), and 
have been using Jenkins for most of those years. Most of our inhouse 
software is C++ though, and a few Java.

I was thinking of creating a custom view plugin to Jenkins for our company. 
Our developers are not happy with the Jenkins UI (Blue Ocean is a step 
forward, but it is still slow and doesn't support customization on 
pipelines view). They feel it is difficult to get an overview which release 
branches has failed, as all the user branches are getting in the way of 
that on Multibranch Pipeline jobs. 

It is hard to convince my peers that Jenkins is much better than our 
inhouse legacy CI system (bunch of ruby scripts, which a single developer 
now has revamped with a Vue.js frontend) for people that has never used a 
third party CI system like Jenkins. The arguments I frequent hear is why 
use resources with Jenkins when there is already a functional CI system. 
They (He) feels all the work I have put in pipelines is wasted, and that we 
should abandon Jenkins to build releases. Well, enough about that (I just 
had to went a little about my reason for creating a custom view plugin).

The plugin I was thinking of creating should list projects with branches 
status. Usually with multibranch pipelines you would have to click on the 
project to get the list of branches, but I wanted the view plugin to list 
branches along with the project on the view page.

Currently I want to start simple, by just listing all the projects and get 
it up and running on Jenkins.

I am seeking some good documentation, howto's for creating Jenkins plugins, 
specifically a View plugin.
https://wiki.jenkins.io/display/JENKINS/Plugin+tutorial
This tutorial revolves around creating a Builder. Could not find a tutorial 
for creating a view plugin, so I will start with this one.
http://www.baeldung.com/jenkins-custom-plugin

Even a visual simple view plugin like jenkins-build-monitor-plugin 
, looks very 
complex. I am getting lost in all the source code. Most of it probably not 
relevant for my plugin.
A reckon a view plugin is half Java code, half HTML/Javascript/CSS code, 
and some jelly it seems also.
https://wiki.jenkins.io/display/JENKINS/Basic+guide+to+Jelly+usage+in+Jenkins

Having browsed this jenkins-build-monitor-plugin 
 on GitHub I am 
overwhelmed. It has almost chased me away, but not quite. I think I must 
start small, just the few bits I need to get a view plugin up to display 
some projects, get the basic feel of the building blocks.


Generating the maven project

mvn archetype:generate -Dfilter=io.jenkins.archetypes:plugin

[INFO] No archetype defined. Using maven-archetype-quickstart 
(org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
Choose archetype:
1: remote -> io.jenkins.archetypes:empty-plugin (Skeleton of a Jenkins plugin 
with a POM and an empty source tree.)
2: remote -> io.jenkins.archetypes:global-configuration-plugin (Skeleton of a 
Jenkins plugin with a POM and an example piece of global configuration.)
3: remote -> io.jenkins.archetypes:hello-world-plugin (Skeleton of a Jenkins 
plugin with a POM and an example build step.)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive 
contains): : 1
Choose io.jenkins.archetypes:empty-plugin version:  

1: 1.0
2: 1.1
3: 1.2
4: 1.3
5: 1.4
Choose a number: 5: 5
I Went through the pom.xml and updated some values

 2.117
 8

Currently no source files yet in my plugin, nor tests. Running mvn install 
fails:
[ERROR] Errors:  
[ERROR] 
org.junit.runner.manipulation.Filter.initializationError(org.junit.runner.manipulation.Filter)
 
[ERROR]   Run 1: Filter.initializationError »  No tests found matching 
Method org.jvnet.hudson 
[ERROR]   Run 2: Filter.initializationError »  No runnable methods 
[ERROR]   Run 3: Filter.initializationError »  No runnable methods 
[ERROR]   Run 4: Filter.initializationError »  No runnable methods 
[INFO]  
[ERROR]   FailedTest.org.jvnet.hudson.test.JellyTestSuiteBuilder$JellyTestSuite 
» FailingHttpStatusCode 
[INFO]  
[ERROR] Tests run: 2, Failures: 0, Errors: 2, Skipped: 0

What kind of test is this? There is nothing in my newly created project.

-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/b0320f5b-97fc-4c22-985a-607e9dc7bb5e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [DISCUSS] Time for Jenkins to require Java 8 to run

2016-10-14 Thread Sverre Moe
Its a good move

SUSE distributions which has OpenJDK 8:
SLES 12 SP1
OpenSUSE 13.2
OpenSUSE Leap 42.1

fredag 14. oktober 2016 10.11.27 UTC+2 skrev Daniel Beck følgende:
>
>
> > On 14.10.2016, at 09:10, nicolas de loof  > wrote: 
> > 
> > About system that don't have Java 8 in official repo (RHEL5, Debian 
> Wheezy, Ubuntu 14.04 LTS). 
>
> Are you saying that RHEL 6 + 7, Debian Jessie, and Ubuntu 16.04 all _do_ 
> have JRE 8 in their repos? 
>
> What about the other distros that have Jenkins packages? openSUSE, Gentoo, 
> and the BSDs? 
>
> Any problems we anticipate for bundling JRE 8 with the Windows installer? 
> (FWIW this could be done early, no need to wait for the runtime 
> requirement…) 
>
>

-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/3653df20-a5d9-4907-9810-3a5d778954fb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: WorkflowMultiBranchProject getLastBuild

2016-08-09 Thread Sverre Moe

>
> On Mon, Aug 8, 2016 at 4:31 AM, Sverre Moe <sverr...@gmail.com 
> > wrote: 
> > I just need the last build from an upstream dependency. The upstream 
> build 
> > cause might be an upstream dependency, or it may be an SCM cause. Such 
> that 
> > the upstream project might not be the upstream cause. Also an upstream 
> cause 
> > might be a downstream dependency. 
>
> Did not really follow that, but… 
>

The project that is currently building might have previously been triggered 
by an upstream project, a component it has as a build dependency with.
So the Upstream Cause which triggered a new build might either be an SCM 
change or another jenkins project.

   A
 /\
B   C
  /\\
 D   EF

* SCM change triggers a build of A.
* The Verification stage triggers a build of B, C, D, E
* The build of B fails and consequently so does A.
...
* SCM change triggers a build of B.
* The Verification stage triggers a build of D and E.
* The build succeeds and so does all its downstream dependencies.
* Now it needs to rebuild A. It checks if the previous build of A failed 
because of this project.

So the upstream build cause might either be an upstream dependency or a 
downstream dependency.

> Later, when one of those downstream dependencies are built from SCM 
> changes. 
> > Lets say when they fixed the issues that previously failed their build 
> > against the upstream project. Now they need to trigger a build of the 
> all 
> > upstream projects (if they previously failed because of this project). 
> After 
> > building a project I needed to get the previous build from an upstream 
> > project to determine if it failed because of this one. 
>
> Seems like it would be easier to roll this into one project with 
> multiple `checkout`s, which could use `currentBuild.changesets` to 
> decide whether or not to rebuild certain components. 
>

Not sure what you ment with that. We have aprox 70 git repositories of 
libraries, utilities, programs with various dependencies among them. Some 
have many dependencies, some have few and some have none.
When someone push changes to remote, the git server has a hook that calls 
Jenkins URL with notifyCommit to trigger a build of that project.

-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/fa96b5b4-8d61-4d13-bd83-95a228715c03%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: WorkflowMultiBranchProject getLastBuild

2016-08-08 Thread Sverre Moe
It is related somewhat. That issue is about getting the upstream build that 
triggered this running build.
I just need the last build from an upstream dependency. The upstream build 
cause might be an upstream dependency, or it may be an SCM cause. Such that 
the upstream project might not be the upstream cause. Also an upstream 
cause might be a downstream dependency.

When a project is building, it triggers a build of all its downstream 
dependencies to verify they work with the new changes. If any of the 
downstream dependencies fail, then also the upstream project should fail. I 
add a BadgeAction with the list of failed downstream projects to the build 
for later inspection.

Later, when one of those downstream dependencies are built from SCM 
changes. Lets say when they fixed the issues that previously failed their 
build against the upstream project. Now they need to trigger a build of the 
all upstream projects (if they previously failed because of this project). 
After building a project I needed to get the previous build from an 
upstream project to determine if it failed because of this one.

fredag 5. august 2016 22.00.34 UTC+2 skrev Jesse Glick følgende:
>
> On Fri, Aug 5, 2016 at 4:02 AM, Sverre Moe <sverr...@gmail.com 
> > wrote: 
> > Variable currentBuild irefers to the currently running build. What I 
> needed 
> > was the last build of a upstream dependency. 
>
> Like JENKINS-31576 you mean? 
>

-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/34cabeb4-bdf4-4ccc-909a-1d4bf51917a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: WorkflowMultiBranchProject getLastBuild

2016-08-05 Thread Sverre Moe
Pipeline Syntax -> Global Variables Reference
Variable currentBuild irefers to the currently running build. What I needed 
was the last build of a upstream dependency.

org.jenkinsci.plugins.workflow.job.WorkflowJob job = anotherUpstreamProject.
getAllJobs().first()
org.jenkinsci.plugins.workflow.job.WorkflowRun build = job.getLastBuild()
hudson.model.Result result = build.getResult()
List badges = build.getBadgeActions()


torsdag 4. august 2016 16.53.54 UTC+2 skrev Jesse Glick følgende:
>
> On Wed, Aug 3, 2016 at 5:14 AM, Sverre Moe <sverr...@gmail.com 
> > wrote: 
> > I need to get the latest build job in my Groovy build script. 
>
> Did you look at the documentation under Global Variables for 
> `currentBuild`? 
>

-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/00f760d3-e9ad-467f-a858-87d4e281eb67%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: WorkflowMultiBranchProject getLastBuild

2016-08-03 Thread Sverre Moe
With some experimenting I think I have gotten what I need.
def jenkinsInstance = jenkins.model.Jenkins.getInstance()
def jenkinsProject = "multiBranchPipelineProjectA/master"
def project = jenkinsInstance.getItemByFullName(jenkinsProject)
def job = project.getAllJobs().first()
def lastBuild = job.getLastBuild()
def completed = !lastBuild.isBuilding()

Method getAllJobs() returns only one Job. Why is that?
I guess that if I called getAllJobs on the Multibranch pipeline project I 
would get for all branches (for instance 4 branches = 4 jobs).

onsdag 3. august 2016 11.14.33 UTC+2 skrev Sverre Moe følgende:
>
> Have Jenkins projects as Multibranch pipeline:
> org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject
>   extends jenkins.branch.MultiBranchProject
> extends com.cloudbees.hudson.plugins.folder.computed.ComputedFolder
>   extends com.cloudbees.hudson.plugins.folder.AbstractFolder
> extends hudson.model.AbstractItem
>
> I need to get the latest build job in my Groovy build script. Jenkins 
> Javadoc is available online, but other APIs are not. It makes it difficult 
> to know which methods I have access to.
>
> WorkflowMultiBranch does not extend AbstractProject which has easy access 
> methods such getLastBuild() or getLastCompletedBuild(). Not having access 
> to the Javadoc for Cloudbees or Branch-API I am unsure if such a method 
> exists for either MultiBranchProject, ComputedFolder or AbstractFolder.
> Go searching through the source code for access methods is tedious and 
> time consuming.
>
> MultiBranchProject: 
> https://github.com/jenkinsci/branch-api-plugin/blob/master/src/main/java/jenkins/branch/MultiBranchProject.java
> ComputedFolder: 
> https://github.com/jenkinsci/cloudbees-folder-plugin/blob/master/src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java
> AbstractFolder: 
> https://github.com/jenkinsci/cloudbees-folder-plugin/blob/master/src/main/java/com/cloudbees/hudson/plugins/folder/AbstractFolder.java
>
> Anyway that is what I was forced to do with no access to such Javadocs.
> Could not find any such easy access methods as those in hudson.model.Job 
> or hudson.model.AbstractProject.
>
> Can get all jobs from AbstractItem
> public abstract Collection getAllJobs()
> And pick the first in the list (if the first is the latest build).
>

-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/24574a4f-b80c-43f6-be95-f54b4935e4f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


WorkflowMultiBranchProject getLastBuild

2016-08-03 Thread Sverre Moe
Have Jenkins projects as Multibranch pipeline:
org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject
  extends jenkins.branch.MultiBranchProject
extends com.cloudbees.hudson.plugins.folder.computed.ComputedFolder
  extends com.cloudbees.hudson.plugins.folder.AbstractFolder
extends hudson.model.AbstractItem

I need to get the latest build job in my Groovy build script. Jenkins 
Javadoc is available online, but other APIs are not. It makes it difficult 
to know which methods I have access to.

WorkflowMultiBranch does not extend AbstractProject which has easy access 
methods such getLastBuild() or getLastCompletedBuild(). Not having access 
to the Javadoc for Cloudbees or Branch-API I am unsure if such a method 
exists for either MultiBranchProject, ComputedFolder or AbstractFolder.
Go searching through the source code for access methods is tedious and time 
consuming.

MultiBranchProject: 
https://github.com/jenkinsci/branch-api-plugin/blob/master/src/main/java/jenkins/branch/MultiBranchProject.java
ComputedFolder: 
https://github.com/jenkinsci/cloudbees-folder-plugin/blob/master/src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java
AbstractFolder: 
https://github.com/jenkinsci/cloudbees-folder-plugin/blob/master/src/main/java/com/cloudbees/hudson/plugins/folder/AbstractFolder.java

Anyway that is what I was forced to do with no access to such Javadocs.
Could not find any such easy access methods as those in hudson.model.Job or 
hudson.model.AbstractProject.

Can get all jobs from AbstractItem
public abstract Collection getAllJobs()
And pick the first in the list (if the first is the latest build).

-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/997498f0-7f23-4b56-932b-203f1976de4d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Calling scheduleBuild2 does not pass along parameters

2016-06-07 Thread Sverre Moe
I defined it in the wrong place it looks like
This project is parameterized
Boolean Parameter
Then the parameter was passed to the downstream build

tirsdag 7. juni 2016 13.11.05 UTC+2 skrev Sverre Moe følgende:
>
> I tried that
> In the downstream job configuration:
> Prepare an environment for the run -> Properties Content 
> -> UPSTREAM_TRIGGERED=false
> Did not work.
>
> tirsdag 7. juni 2016 12.57.21 UTC+2 skrev Antonio Muñiz følgende:
>>
>> On Tue, Jun 7, 2016 at 12:52 PM, Sverre Moe <sverr...@gmail.com> wrote: 
>> > How/where do i define the parameter? 
>>
>>
>> The parameter must be defined in the downstream job (as any other 
>> parameterized job). 
>>
>> -- 
>> Antonio Muñiz 
>> Software Engineer 
>> CloudBees, Inc. 
>>
>

-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/e39cd4fa-fcd8-4e50-b2d9-3a4a142e2999%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Calling scheduleBuild2 does not pass along parameters

2016-06-07 Thread Sverre Moe
I tried that
In the downstream job configuration:
Prepare an environment for the run -> Properties Content 
-> UPSTREAM_TRIGGERED=false
Did not work.

tirsdag 7. juni 2016 12.57.21 UTC+2 skrev Antonio Muñiz følgende:
>
> On Tue, Jun 7, 2016 at 12:52 PM, Sverre Moe <sverr...@gmail.com 
> > wrote: 
> > How/where do i define the parameter? 
>
>
> The parameter must be defined in the downstream job (as any other 
> parameterized job). 
>
> -- 
> Antonio Muñiz 
> Software Engineer 
> CloudBees, Inc. 
>

-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/679c1d15-bf59-45f0-917e-a72a56df1321%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Calling scheduleBuild2 does not pass along parameters

2016-06-07 Thread Sverre Moe
Using Jenkins 2.8.

How/where do i define the parameter?

1) For regular build jobs
Tried: Prepare an environment for the run -> Properties Content 
-> UPSTREAM_TRIGGERED=false
Did not work. The value if always false, even if ProjectA sends the value 
with true.

2) For pipeline jobs
Tried: withEnv(["UPSTREAM_TRIGGERED=true"]) {
Did not work

tirsdag 7. juni 2016 12.34.38 UTC+2 skrev Antonio Muñiz følgende:
>
> If you are using Jenkins 1.651.2 (or 2.3+) you are hitting the 
> SECURITY-170 fix: undeclared parameters are ignored (and not injected 
> as env vars). 
> You have to define the parameter (`UPSTREAM_TRIGGERED`) in the downstream 
> build. 
>
> On Tue, Jun 7, 2016 at 9:39 AM, Sverre Moe <sverr...@gmail.com 
> > wrote: 
> > I am trying to pass a parameter to a scheduled build, but the build does 
> not 
> > get the parameter. 
> > 
> > When ProjectA schedule a build of ProjectB it should pass along a 
> parameter 
> > I called UPSTREAM_TRIGGERED. 
> > When ProjectB starts building there are no parameters passed in from 
> > ProjectA. 
> > 
> > I have the following Groovy Postbuild script running. 
> > #!/usr/bin/env groovy 
> > 
> > import jenkins.model.Jenkins 
> > import hudson.matrix.MatrixProject 
> > import hudson.matrix.MatrixBuild; 
> > import hudson.matrix.MatrixRun; 
> > import hudson.console.ModelHyperlinkNote 
> > import hudson.model.Action 
> > import hudson.model.Cause 
> > import hudson.model.ParametersAction 
> > import hudson.model.ParametersDefinitionProperty 
> > import hudson.model.BooleanParameterValue 
> > import hudson.model.Cause.UpstreamCause 
> > import hudson.model.queue.QueueTaskFuture 
> > import hudson.model.Result 
> > 
> > if (manager.buildIsA(MatrixBuild.class)) { 
> > final def build = manager.build 
> > final def buildProject = build.getParent() 
> > 
> > def upstreamTrigger = false 
> > def upstreamTriggerValue = manager.envVars['UPSTREAM_TRIGGERED'] 
> > if (upstreamTriggerValue != null && !upstreamTriggerValue.isEmpty()) 
> { 
> > upstreamTrigger = Boolean.parseBoolean(upstreamTriggerValue) 
> > } 
> > 
> > if (upstreamTrigger) { 
> > return 
> > } 
> > 
> > final def downstreamProjects = 
> manager.envVars['DOWNSTREAM_PROJECTS'] 
> > if (downstreamProjects != null) { 
> > final def downstreamProjectsList = downstreamProjects.split(", 
> > ").toList() 
> > 
> > final def preliminaryResult = build.getResult() 
> > if (preliminaryResult.isBetterOrEqualTo(Result.SUCCESS)) { 
> > downstreamProjectsList.each { projectName -> 
> > def project = 
> > Jenkins.instance.getItemByFullName(projectName) 
> > if (project == null) { 
> > manager.listener.logger.println("Cannot schedule 
> build. 
> > Poject " + projectName + " does not exist") 
> > return 
> > } 
> > 
> > if (project.isDisabled()) { 
> > manager.listener.logger.println("Project " + 
> > ModelHyperlinkNote.encodeTo(project) + " disabled. Skipping build") 
> > return 
> > } 
> > 
> > def params = [] 
> > def extraParameterValue = new 
> > BooleanParameterValue('UPSTREAM_TRIGGERED', true) 
> > params.add(extraParameterValue) 
> > 
> > /* Add the project's default parameters */ 
> > def parametersDefProp = 
> > project.getProperty(ParametersDefinitionProperty.class) 
> > parametersDefProp.getParameterDefinitions().each { param 
> -> 
> > def parameterValue = 
> param.getDefaultParameterValue() 
> > params.add(parameterValue) 
> > } 
> > 
> > def parametersAction = new ParametersAction(params) 
> > 
> > def cause = new UpstreamCause(build) 
> > manager.listener.logger.println("Schedule job " + 
> > ModelHyperlinkNote.encodeTo(project)) 
> > def futureTask = 
> project.scheduleBuild2(project.quietPeriod, 
> > cause, parametersAction) 
> > 
> > if (futureTask == null) { 
> > manager.listener.logger.println("Unable to schedule 
> job 
> > for " + ModelHy

Calling scheduleBuild2 does not pass along parameters

2016-06-07 Thread Sverre Moe
I am trying to pass a parameter to a scheduled build, but the build does 
not get the parameter.

When ProjectA schedule a build of ProjectB it should pass along a parameter 
I called UPSTREAM_TRIGGERED.
When ProjectB starts building there are no parameters passed in from 
ProjectA.

I have the following Groovy Postbuild script running.
#!/usr/bin/env groovy

import jenkins.model.Jenkins
import hudson.matrix.MatrixProject
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixRun;
import hudson.console.ModelHyperlinkNote
import hudson.model.Action
import hudson.model.Cause
import hudson.model.ParametersAction
import hudson.model.ParametersDefinitionProperty
import hudson.model.BooleanParameterValue
import hudson.model.Cause.UpstreamCause
import hudson.model.queue.QueueTaskFuture
import hudson.model.Result

if (manager.buildIsA(MatrixBuild.class)) {
final def build = manager.build
final def buildProject = build.getParent()

def upstreamTrigger = false
def upstreamTriggerValue = manager.envVars['UPSTREAM_TRIGGERED']
if (upstreamTriggerValue != null && !upstreamTriggerValue.isEmpty()) {
upstreamTrigger = Boolean.parseBoolean(upstreamTriggerValue)
}

if (upstreamTrigger) {
return
}

final def downstreamProjects = manager.envVars['DOWNSTREAM_PROJECTS']
if (downstreamProjects != null) {
final def downstreamProjectsList = downstreamProjects.split(", 
").toList()

final def preliminaryResult = build.getResult()
if (preliminaryResult.isBetterOrEqualTo(Result.SUCCESS)) {
downstreamProjectsList.each { projectName ->
def project = 
Jenkins.instance.getItemByFullName(projectName)
if (project == null) {
manager.listener.logger.println("Cannot schedule build. 
Poject " + projectName + " does not exist")
return
}

if (project.isDisabled()) {
manager.listener.logger.println("Project " + 
ModelHyperlinkNote.encodeTo(project) + " disabled. Skipping build")
return
}

def params = []
def extraParameterValue = new 
BooleanParameterValue('UPSTREAM_TRIGGERED', true)
params.add(extraParameterValue)

/* Add the project's default parameters */
def parametersDefProp = 
project.getProperty(ParametersDefinitionProperty.class)
parametersDefProp.getParameterDefinitions().each { param ->
def parameterValue = param.getDefaultParameterValue()
params.add(parameterValue)
}

def parametersAction = new ParametersAction(params)

def cause = new UpstreamCause(build)
manager.listener.logger.println("Schedule job " + 
ModelHyperlinkNote.encodeTo(project))
def futureTask = 
project.scheduleBuild2(project.quietPeriod, cause, parametersAction)

if (futureTask == null) {
manager.listener.logger.println("Unable to schedule job 
for " + ModelHyperlinkNote.encodeTo(project))
manager.buildUnstable()
return
}

MatrixBuild startedBuild = futureTask.waitForStart();
if (startedBuild == null) {
manager.listener.logger.println("Failed to start " + 
ModelHyperlinkNote.encodeTo(project))
manager.buildUnstable()
return
}

manager.listener.logger.println("Build " + 
ModelHyperlinkNote.encodeTo('/'+ startedBuild.getUrl(), 
startedBuild.getFullDisplayName()) + " started")
MatrixBuild finishedBuild = futureTask.get()
def finishedBuildResult = finishedBuild.getResult()


manager.listener.logger.println(ModelHyperlinkNote.encodeTo('/'+ 
finishedBuild.getUrl(), 
finishedBuild.getFullDisplayName()) + " completed 
with result " + finishedBuildResult)

if (finishedBuildResult.isWorseThan(Result.SUCCESS)) {
manager.buildUnstable()
}
}
}
} else {
manager.listener.logger.println("No downstream projects to trigger")
}
}

I included the complete script for measure. I believe the problem lies with 
this code snippet in the script
def params = []
def extraParameterValue = new BooleanParameterValue('UPSTREAM_TRIGGERED', 
true)
params.add(extraParameterValue)

/* Add the project's default parameters */
def parametersDefProp = 
project.getProperty(ParametersDefinitionProperty.class)
parametersDefProp.getParameterDefinitions().each { param ->
def parameterValue = param.getDefaultParameterValue()
params.add(parameterValue)
}

def parametersAction = new ParametersAction(params)

def cause = new UpstreamCause(build)

Re: Transfers artifacts using SCP with Groovy and Jenkins API

2016-05-27 Thread Sverre Moe
I found the plugin SSH Agent where I could access SSH credentials. However 
I'm still not sure how to use it in Groovy Postbuild to transfer files to 
the server.

I could find a Pipeline example using the SSH Agent Plugin:
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 
'MyID', usernameVariable: 'GIT_USERNAME', passwordVariable: 
'GIT_PASSWORD']]) {
sh("git tag -a some_tag -m 'Jenkins'")
sh('git push https://${GIT_USERNAME}:${GIT_PASSWORD}@ --tags')
}


My current implementation is using "Send build artifacts over SSH" in 
Flexible Publish.  It is big, complex and hard to maintain. I haven't given 
up to do the same in Groovy Postbuild script. As a fallback I was thinking 
of just manually copy ssh public key to server and use Bash script to scp 
the files. No one else have used Groovy postbuild to transfer files to 
server or at least know how?



onsdag 15. april 2015 15.58.21 UTC+2 skrev Sverre Moe følgende:
>
> Instead of using "Send build artifacts over SSH" I would like to do the 
> same using a Groovy script (Groovy Postbuild, as it would have access to 
> the Jenkins API).
>
> I would rather have this in a Groovy script, because I need to perform 
> some extra logic for the files. Also because many transfer sets takes a lot 
> of space (scrolling madness).
>
> The Groovy script must get the SSH Server defined in Jenkins 
> configuration, then transfer files over SCP.
>
> Is it possible? Can I do it within Groovy and access to the Jenkins API?
>
> I tried looking into the Jenkins API Javadoc, but could not find any 
> method to gain access to the SSH Server defined in Jenkins Configuration.
>
>
> Having access to the workspace through Jenkins API I could perhaps do 
> something like this:
> import hudson.FilePath.FileCallable
> import hudson.remoting.VirtualChannel
>
> def jenkinsInstance = jenkins.model.Jenkins.getInstance()
> def project = jenkinsInstance.getItem("myMatrixProject")
> def someWorkspace = project.getSomeWorkspace()
>
> //SSH Server information: If this is possible
> def sshServer = jenkinsInstance.getSshServer("mySshServer")
> def host = sshServer.getHost()
> def user = sshServer.getUsername()
> def password = sshServer.getPassword()
> //SSH Server information
>
> private class ScpFileCallable implements FileCallable {
>   private static final long serialVersionUID = 1L;
>   @Override
>   public String invoke(File file, VirtualChannel channel) throws 
> IOException, InterruptedException {
> /*
>  * Find the files and transfer them over SCP
>  */
>   }
>  
>   @Override
>   public void checkRoles(RoleChecker checker) throws SecurityException {
> 
>   }
> }
>
> try { 
>someWorkspace.act(new ScpFileCallable());
> } catch (IOException e) { 
> println e.getMessage()
> } catch (InterruptedException e) { 
> println e.getMessage()
> }
>
>
>

-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/37c7eb10-bffc-48da-8d8a-8f7602c4d1d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Groovy project.save() does not always work

2016-04-18 Thread Sverre Moe
That was the problem. Thank you.
I found that there was duplicate EnvInjectJobProperty within config.xml

I will update my script to remove the existing before adding the new.

mandag 18. april 2016 12.31.57 UTC+2 skrev Daniel Beck følgende:
>
> You're never removing any potentially existing job properties, just 
> adding. So it's likely you just get the old one returned from your API 
> call, as the job properties list does not really support having two of the 
> same type (but doesn't prevent it either). Confirm by looking at the 
> config.xml. 
>
> > On 18.04.2016, at 09:27, Sverre Moe <sverr...@gmail.com > 
> wrote: 
> > 
> > I am not sure what I am doing wrong with my groovy script. 
> > I have written a groovy update script to bulk update all my projects. 
> > Sometimes it does not take affect when I call project.save() 
> > I can afterwards open that project configuration page and everything 
> looks right. The updated content is there. 
> > However when I write a groovy read script to print out that information 
> I updated, not all projects show the updated information. 
> > If I then open those projects configuration page, do nothing and just 
> press save then that information is available when I run the read script 
> again. 
> > 
> > Making a change in Script console using Groovy and then envoke 
> project.save(), why is it that when I try to read the value again it does 
> not show the changed value, but the old one. 
> > 
> > Do I need to perform some other action than just project.save() 
> > 
> > For instance given this groovy script to add some environment variables. 
> > #!/usr/bin/env groovy 
> > 
> > import java.lang.StringBuilder 
> > import hudson.matrix.MatrixProject 
> > import org.jenkinsci.plugins.envinject.EnvInjectJobProperty 
> > import org.jenkinsci.plugins.envinject.EnvInjectJobPropertyInfo 
> > 
> > def jenkinsInstance = jenkins.model.Jenkins.getInstance() 
> > def developmentView = jenkinsInstance.getView("myView") 
> > developmentView.getItems().each { project -> 
> > 
> > StringBuilder builder = new StringBuilder() 
> > builder.append("NO_CPPCHECK=true") 
> > builder.append("\n") 
> > builder.append("NO_INSTALL=true") 
> > final def propertiesContent = builder.toString() 
> > 
> > def info = new EnvInjectJobPropertyInfo(null, propertiesContent, 
> null, null, null, false) 
> > def property = new EnvInjectJobProperty() 
> > property.setOn(true) 
> > property.setKeepJenkinsSystemVariables(true) 
> > property.setKeepBuildVariables(true) 
> > property.setInfo(info) 
> > 
> > project.addProperty(property) 
> > project.save() 
> > } 
> > 
> > Trying to read the same environment variables 
> > #!/usr/bin/env groovy 
> > 
> > import org.jenkinsci.plugins.envinject.EnvInjectJobProperty 
> > import org.jenkinsci.plugins.envinject.EnvInjectJobPropertyInfo 
> > 
> > def jenkinsInstance = jenkins.model.Jenkins.getInstance() 
> > def developmentView = jenkinsInstance.getView("myView") 
> > developmentView.getItems().each { project -> 
> >   def EnvInjectJobProperty property = 
> project.getProperty(EnvInjectJobProperty.class) 
> >   if (property != null) { 
> > def info = property.getInfo() 
> > println info.getPropertiesContent() 
> >   } 
> > } 
> > 
> > Not all projects now shows the environment variables. 
> > 
> > -- 
> > 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/37b712cb-5407-4359-bacd-37a700ef8aed%40googlegroups.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>
>

-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/38857f6a-357e-4f54-bb88-58e3d50144c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Groovy project.save() does not always work

2016-04-18 Thread Sverre Moe
I am not sure what I am doing wrong with my groovy script.
I have written a groovy update script to bulk update all my projects.
Sometimes it does not take affect when I call project.save()
I can afterwards open that project configuration page and everything looks 
right. The updated content is there.
However when I write a groovy read script to print out that information I 
updated, not all projects show the updated information.
If I then open those projects configuration page, do nothing and just press 
save then that information is available when I run the read script again.

Making a change in Script console using Groovy and then envoke 
project.save(), why is it that when I try to read the value again it does 
not show the changed value, but the old one.

Do I need to perform some other action than just project.save()

For instance given this groovy script to add some environment variables.
#!/usr/bin/env groovy

import java.lang.StringBuilder
import hudson.matrix.MatrixProject
import org.jenkinsci.plugins.envinject.EnvInjectJobProperty
import org.jenkinsci.plugins.envinject.EnvInjectJobPropertyInfo

def jenkinsInstance = jenkins.model.Jenkins.getInstance()
def developmentView = jenkinsInstance.getView("myView")
developmentView.getItems().each { project ->

StringBuilder builder = new StringBuilder()
builder.append("NO_CPPCHECK=true")
builder.append("\n")
builder.append("NO_INSTALL=true")
final def propertiesContent = builder.toString()

def info = new EnvInjectJobPropertyInfo(null, propertiesContent, null, 
null, null, false)
def property = new EnvInjectJobProperty()
property.setOn(true)
property.setKeepJenkinsSystemVariables(true)
property.setKeepBuildVariables(true)
property.setInfo(info)

project.addProperty(property)
project.save()
}

Trying to read the same environment variables
#!/usr/bin/env groovy

import org.jenkinsci.plugins.envinject.EnvInjectJobProperty
import org.jenkinsci.plugins.envinject.EnvInjectJobPropertyInfo

def jenkinsInstance = jenkins.model.Jenkins.getInstance()
def developmentView = jenkinsInstance.getView("myView")
developmentView.getItems().each { project ->
  def EnvInjectJobProperty property = project.getProperty(
EnvInjectJobProperty.class)
  if (property != null) {
def info = property.getInfo()
println info.getPropertiesContent()
  }
}

Not all projects now shows the environment variables.

-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/37b712cb-5407-4359-bacd-37a700ef8aed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [JENKINS-27317] Request for developers

2015-12-03 Thread Sverre Moe
I made an initial fix for this.
https://github.com/jenkinsci/template-project-plugin/pull/26

My latest test with this fix threw an IllegalStateException. I have been 
somewhat busy so I haven't had more time to look into this.

FATAL: cannot change build result while in COMPLETED
java.lang.IllegalStateException: cannot change build result while in COMPLETED
at hudson.model.Run.setResult(Run.java:459)
at 
org.jenkins_ci.plugins.run_condition.BuildStepRunner.setResult(BuildStepRunner.java:64)
at 
org.jenkins_ci.plugins.run_condition.BuildStepRunner.access$200(BuildStepRunner.java:46)
at 
org.jenkins_ci.plugins.run_condition.BuildStepRunner$Fail.conditionalRun(BuildStepRunner.java:151)
at 
org.jenkins_ci.plugins.run_condition.BuildStepRunner.perform(BuildStepRunner.java:105)
at 
org.jenkins_ci.plugins.flexible_publish.strategy.FailFastExecutionStrategy.matrixAggregationEndRun(FailFastExecutionStrategy.java:85)
at 
org.jenkins_ci.plugins.flexible_publish.ConditionalMatrixAggregator.endRun(ConditionalMatrixAggregator.java:82)
at 
org.jenkins_ci.plugins.flexible_publish.FlexibleMatrixAggregator.endRun(FlexibleMatrixAggregator.java:83)
at 
hudson.plugins.templateproject.ProxyMatrixAggregator.endRun(ProxyMatrixAggregator.java:50)
at 
hudson.matrix.DefaultMatrixExecutionStrategyImpl.notifyEndBuild(DefaultMatrixExecutionStrategyImpl.java:220)
at 
hudson.matrix.DefaultMatrixExecutionStrategyImpl.run(DefaultMatrixExecutionStrategyImpl.java:163)
at 
hudson.matrix.MatrixBuild$MatrixBuildExecution.doRun(MatrixBuild.java:352)
at 
hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:537)
at hudson.model.Run.execute(Run.java:1741)
at hudson.matrix.MatrixBuild.run(MatrixBuild.java:301)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:410




tirsdag 13. oktober 2015 15.00.24 UTC+2 skrev Baptiste Mathus følgende:
>
> Hi,
> IMO, your best bet is yourself by submitting a pull-request for this. 
>
> If you don't have "much time to look more into this", then your other 
> solution is to pay someone to do this. 
> There are many people/companies available for this 
> <https://wiki.jenkins-ci.org/display/JENKINS/Commercial+Support>.
>
> Cheers
>
> 2015-10-13 14:46 GMT+02:00 Sverre Moe <sverr...@gmail.com >:
>
>> Anyone who is familiar with the Template Project Plugin 
>> <https://wiki.jenkins-ci.org/display/JENKINS/Template+Project+Plugin> who 
>> could take it upon them self to fix the issue JENKINS-27317?
>>
>> I have looked at the source code a little and come up with "fix". My fix 
>> is not tested because I do not have a working development environment for 
>> Jenkins.
>>
>> https://github.com/DJViking/template-project-plugin/commit/f74c0d6b11160eb5762315d712e7fbba1ed036a1
>> However I don't have much time to look more into this.
>>
>> This bug is preventing a vital feature in my groovy post-build script.
>>
>

-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/91880444-8819-4620-bb28-56b248350e44%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


New to Developing Jenkins Plugins: Nexus problem

2015-10-07 Thread Sverre Moe
I have checked out Jenkins template-project-plugin in an effort to fix an 
issue
https://issues.jenkins-ci.org/browse/JENKINS-27317

I have followed the instruction to add Jenkins Maven Repository to my 
existing Nexus, in order to build with Maven.
https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Development+Environment+with+Nexus

Then I proceeded with creating eclipse project files for the 
template-project-plugin:
user@linuxbox:~/workspace/template-project-plugin> mvn eclipse:eclipse
[INFO] Scanning for projects...
Downloading: 
http://companyNexus:8081/nexus/content/groups/public/org/jenkins-ci/plugins/plugin/1.580.1/plugin-1.580.1.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for 
org.jenkins-ci.plugins:template-project:1.5.2-SNAPSHOT: Could not find 
artifact org.jenkins-ci.plugins:plugin:pom:1.580.1 in nexus 
(http://companyNexus:8081/nexus/content/groups/public) and 
'parent.relativePath' points at wrong local POM @ line 3, column 11

Jenkins Summary from my Nexus:
Repository ID: jenkins
Repository Name: Jenkins Releases
Repository Type: proxy
Repository Policy: Release
Repository Format: maven2
Contained in groups: 

Remote URL: http://maven.jenkins-ci.org/content/repositories/releases/

Nexus Discovery:
Unsuccessful.
Message:
Server proxied by M2Repository(id=jenkins) proxy repository is not 
supported by automatic routing discovery

It seems there was some problem with the Jenkins repository. I do not have 
the same problem with the Maven Central proxy.

-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/b800c8ea-dbcf-4cde-b7ba-901c76552773%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: FilePath act fails with an exception

2015-04-16 Thread Sverre Moe
I changed the code to extend MasterToSlaveFileCallable, but the exception 
is still the same.

Changed:
private static class RemoteListDir implements FileCallableSetString { 
To:
private static class RemoteListDir extends 
MasterToSlaveFileCallableSetString { 


Caused by: java.io.IOException: Remote call on Development-opensuse-x86_64 
failed
at hudson.remoting.Channel.call(Channel.java:761)
at hudson.FilePath.act(FilePath.java:978)
... 28 more
Caused by: java.lang.Error: Failed to deserialize the Callable object.
at hudson.remoting.UserRequest.perform(UserRequest.java:105)
at hudson.remoting.UserRequest.perform(UserRequest.java:49)
at hudson.remoting.Request$2.run(Request.java:325)
at 
hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
at ..remote call to Development-opensuse-x86_64(Native Method)
at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1360)
at hudson.remoting.UserResponse.retrieve(UserRequest.java:221)
at hudson.remoting.Channel.call(Channel.java:753)
... 29 more
Caused by: java.lang.IllegalArgumentException: Unable to locate class file for 
class MyClass$RemoteListDir


onsdag 15. april 2015 20.54.40 UTC+2 skrev Jesse Glick følgende:

 On Tue, Mar 24, 2015 at 1:29 PM, Ulli Hafner ullrich...@gmail.com 
 javascript: wrote: 
  You need to implement the new method checkRoles. 

 No, you do not. You just need to use MasterToSlaveFileCallable. 


-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/e318d8ce-8305-4048-bdf2-b35ad8f27049%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Adding a build trigger does add upstream project

2015-04-15 Thread Sverre Moe
Yes, that did the trick.

As an end notice. Using only project.save(), it took aprox. 20 minutes 
before the project main page to show the upstream project.

onsdag 15. april 2015 13.33.51 UTC+2 skrev Jesse Glick følgende:

 On Wed, Apr 15, 2015 at 2:54 AM, Sverre Moe sverr...@gmail.com 
 javascript: wrote: 
  Did not work with project.save() 

 Try: Jenkins.getInstance().rebuildDependencyGraph() 


-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/bebcdc66-ab95-4129-b6f9-38e98823e57d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Adding a build trigger does add upstream project

2015-04-15 Thread Sverre Moe
Did not work with project.save()

Adding the trigger does add the project to the list in Build after other 
projects are built, but that is all. The project is not shown as a 
upstream project.

tirsdag 14. april 2015 18.47.05 UTC+2 skrev Jesse Glick følgende:

 On Tue, Apr 14, 2015 at 12:38 PM, Sverre Moe sverr...@gmail.com 
 javascript: wrote: 
  What am I missing? 

 project.save() perhaps? Not sure if addTrigger implies that. 


-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/13483e5b-c230-43ca-a654-4924f78ef61f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Adding a build trigger does add upstream project

2015-04-14 Thread Sverre Moe
I am able to add a build trigger to a project, but it does not get added to 
the list of upstream projects.

import jenkins.triggers.ReverseBuildTrigger
import hudson.model.Result

def jenkinsInstance = jenkins.model.Jenkins.getInstance()
def project = jenkinsInstance.getItem(myLib2)

def trigger = new ReverseBuildTrigger(myLib1, Result.SUCCESS)
project.addTrigger(trigger)

Project myLib1 does not show any downstream projects on its main page
Project myLib2 does not show any upstream projects on its main page

What am I missing?

There is no setter method for upstream/downstream projects, only a getter.
AbstractProject.getUpstreamProjects()
AbstractProject.getDownstreamProjects()

-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/7ba1b1e7-2571-485b-9b1d-43d19efe0192%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: FilePath act fails with an exception

2015-03-25 Thread Sverre Moe
I have added checkRoles within my FileCallable implementation, but it still 
fails. Though this time with a different message.

remote file operation failed: /home/build/jenkins/workspace/myMatrixProject at 
hudson.remoting.Channel@54e95cec:Development-opensuse-x86_64: 
java.io.IOException: Unable to serialize 
hudson.FilePath$FileCallableWrapper@5a17f7bd


import hudson.FilePath.FileCallable
import hudson.remoting.VirtualChannel
import org.jenkinsci.remoting.RoleChecker

def jenkinsInstance = jenkins.model.Jenkins.getInstance()
def project = jenkinsInstance.getItem(myMatrixProject)
def rootProject = project.getRootProject()
def someWorkspace = rootProject.getSomeWorkspace()

try { 
def test = someWorkspace.act(new FileCallableString() {
private static final long serialVersionUID = 1;
@Override
public String invoke(File file, VirtualChannel channel) {
return Testing Testing;
}
  
@Override
public void checkRoles(RoleChecker checker) throws 
SecurityException {

}
});
  
println test
} catch (IOException e) {
  println e.getMessage()
} catch (InterruptedException e) { 
  println e.getMessage()
}


Could you ellaborate on use the provided abstract base classes as parent ?


tirsdag 24. mars 2015 18.29.12 UTC+1 skrev Ullrich Hafner følgende:

 You need to implement the new method checkRoles. See JavaDoc of latest 
 FileCallable 
 version. (Or you can use the provided abstract base classes as parent).

 Am 24.03.2015 um 18:03 schrieb Sverre Moe sverr...@gmail.com 
 javascript::


 Trying the following in Jenkins Script Console:

 import hudson.FilePath.FileCallable
 import hudson.remoting.VirtualChannel

 def jenkinsInstance = jenkins.model.Jenkins.getInstance()
 def project = jenkinsInstance.getItem(myMatrixProject)
 def rootProject = project.getRootProject()
 def someWorkspace = rootProject.getSomeWorkspace()

 try { 
 def test = someWorkspace.act(new FileCallableString() {
 private static final long serialVersionUID = 1;
 @Override
 public String invoke(File file, VirtualChannel channel) {
 return Testing Testing;
 }
 });
 } catch (IOException e) { 
   e.printStackTrace(); 
 } catch (InterruptedException e) { 
   e.printStackTrace(); 
 }

 It throws an exception:

 org.codehaus.groovy.control.MultipleCompilationErrorsException: startup 
 failed:
 Script1.groovy: 10: Can't have an abstract method in a non-abstract class. 
 The class 'Script1$1' must be declared abstract or the method 'void 
 checkRoles(org.jenkinsci.remoting.RoleChecker)' must be implemented.
  @ line 10, column 61.
ct(new FileCallableString() {


 -- 
 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 javascript:.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/jenkinsci-dev/b2502c2c-8a02-46df-8bce-90ee10724090%40googlegroups.com
  
 https://groups.google.com/d/msgid/jenkinsci-dev/b2502c2c-8a02-46df-8bce-90ee10724090%40googlegroups.com?utm_medium=emailutm_source=footer
 .
 For more options, visit https://groups.google.com/d/optout.




-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/71b59eab-5381-4cf4-becd-2fe7389ad074%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: FilePath act fails with an exception

2015-03-25 Thread Sverre Moe
Tried the following that got rid of Unable to serialize, but still does 
not work. Most of the examples I find online for FilePath.act does not work 
in Script Console.

import hudson.FilePath.FileCallable
import hudson.remoting.VirtualChannel
import org.jenkinsci.remoting.RoleChecker

def jenkinsInstance = jenkins.model.Jenkins.getInstance()
def project = jenkinsInstance.getItem(myMatrixProject)
def rootProject = project.getRootProject()
def someWorkspace = rootProject.getSomeWorkspace()

private class MyFileCallable implements FileCallableString {
  private static final long serialVersionUID = 1L;
  @Override
  public String invoke(File file, VirtualChannel channel) throws 
IOException, InterruptedException {
return Testing Testing;
  }
  
  @Override
  public void checkRoles(RoleChecker checker) throws SecurityException {

  }
}

try { 
def test = someWorkspace.act(new MyFileCallable());
println test
} catch (IOException e) { 
println e.getMessage()
} catch (InterruptedException e) { 
println e.getMessage()
}

remote file operation failed: /home/build/jenkins/workspace/myMatrixProject at 
hudson.remoting.Channel@54e95cec:Development-opensuse-x86_64: 
java.io.IOException: Remote call on Development-opensuse-x86_64 failed



onsdag 25. mars 2015 10.03.35 UTC+1 skrev Sverre Moe følgende:

 I have added checkRoles within my FileCallable implementation, but it 
 still fails. Though this time with a different message.

 remote file operation failed: /home/build/jenkins/workspace/myMatrixProject 
 at hudson.remoting.Channel@54e95cec:Development-opensuse-x86_64: 
 java.io.IOException: Unable to serialize 
 hudson.FilePath$FileCallableWrapper@5a17f7bd


 import hudson.FilePath.FileCallable
 import hudson.remoting.VirtualChannel
 import org.jenkinsci.remoting.RoleChecker

 def jenkinsInstance = jenkins.model.Jenkins.getInstance()
 def project = jenkinsInstance.getItem(myMatrixProject)
 def rootProject = project.getRootProject()
 def someWorkspace = rootProject.getSomeWorkspace()

 try { 
 def test = someWorkspace.act(new FileCallableString() {
 private static final long serialVersionUID = 1;
 @Override
 public String invoke(File file, VirtualChannel channel) {
 return Testing Testing;
 }
   
 @Override
 public void checkRoles(RoleChecker checker) throws 
 SecurityException {
 
 }
 });
   
 println test
 } catch (IOException e) {
   println e.getMessage()
 } catch (InterruptedException e) { 
   println e.getMessage()
 }


 Could you ellaborate on use the provided abstract base classes as 
 parent ?


 tirsdag 24. mars 2015 18.29.12 UTC+1 skrev Ullrich Hafner følgende:

 You need to implement the new method checkRoles. See JavaDoc of latest 
 FileCallable 
 version. (Or you can use the provided abstract base classes as parent).

 Am 24.03.2015 um 18:03 schrieb Sverre Moe sverr...@gmail.com:


 Trying the following in Jenkins Script Console:

 import hudson.FilePath.FileCallable
 import hudson.remoting.VirtualChannel

 def jenkinsInstance = jenkins.model.Jenkins.getInstance()
 def project = jenkinsInstance.getItem(myMatrixProject)
 def rootProject = project.getRootProject()
 def someWorkspace = rootProject.getSomeWorkspace()

 try { 
 def test = someWorkspace.act(new FileCallableString() {
 private static final long serialVersionUID = 1;
 @Override
 public String invoke(File file, VirtualChannel channel) {
 return Testing Testing;
 }
 });
 } catch (IOException e) { 
   e.printStackTrace(); 
 } catch (InterruptedException e) { 
   e.printStackTrace(); 
 }

 It throws an exception:

 org.codehaus.groovy.control.MultipleCompilationErrorsException: startup 
 failed:
 Script1.groovy: 10: Can't have an abstract method in a non-abstract class. 
 The class 'Script1$1' must be declared abstract or the method 'void 
 checkRoles(org.jenkinsci.remoting.RoleChecker)' must be implemented.
  @ line 10, column 61.
ct(new FileCallableString() {


 -- 
 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/b2502c2c-8a02-46df-8bce-90ee10724090%40googlegroups.com
  
 https://groups.google.com/d/msgid/jenkinsci-dev/b2502c2c-8a02-46df-8bce-90ee10724090%40googlegroups.com?utm_medium=emailutm_source=footer
 .
 For more options, visit https://groups.google.com/d/optout.




-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/542700b1-0571-4bf8-b6bc

FilePath act fails with an exception

2015-03-24 Thread Sverre Moe
Trying the following in Jenkins Script Console:

import hudson.FilePath.FileCallable
import hudson.remoting.VirtualChannel

def jenkinsInstance = jenkins.model.Jenkins.getInstance()
def project = jenkinsInstance.getItem(myMatrixProject)
def rootProject = project.getRootProject()
def someWorkspace = rootProject.getSomeWorkspace()

try { 
def test = someWorkspace.act(new FileCallableString() {
private static final long serialVersionUID = 1;
@Override
public String invoke(File file, VirtualChannel channel) {
return Testing Testing;
}
});
} catch (IOException e) { 
  e.printStackTrace(); 
} catch (InterruptedException e) { 
  e.printStackTrace(); 
}

It throws an exception:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 10: Can't have an abstract method in a non-abstract class. The 
class 'Script1$1' must be declared abstract or the method 'void 
checkRoles(org.jenkinsci.remoting.RoleChecker)' must be implemented.
 @ line 10, column 61.
   ct(new FileCallableString() {

-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/b2502c2c-8a02-46df-8bce-90ee10724090%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Run Groovy script only on Matrix parent

2015-03-18 Thread Sverre Moe
The groovy script executed by Groovy Postbuild does not run on Matrix 
parent if this Post build publisher comes from a template project.
There is an issue for this: 
https://issues.jenkins-ci.org/browse/JENKINS-27317

I order for the script to run on my several hundred jobs I would have to 
duplicate this script under each job. Maintenance would be a nightmare.

Thankfully Execute System Groovy script could load the script from a file, 
thus I solve my script duplication problem. It exposes some of the same 
variables as Groovy Postbuild, such as the current build. However I cannot 
get the script to run only on Matrix parent

Build - Execute System Groovy script - Script command
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixRun;

if (build instanceof MatrixRun) {
  println MatrixRun child 
} else if (build instanceof MatrixBuild) {
  println MatrixBuild parent 
}
It seems it only runs on each matrix build configurations (childs).

-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/30a70a84-dfce-49fe-91b1-602d995ce406%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Run Groovy script only on Matrix parent

2015-03-18 Thread Sverre Moe
I came by an immediate fix:

Using this Groovy Postbuild script on all my jobs

import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixRun;

if (manager.buildIsA(MatrixBuild.class)) {
evaluate(new File(build-downstream-projects.groovy))
}


A little bit duplication, but the main logic remains in the groovy script 
file.


onsdag 18. mars 2015 12.24.23 UTC+1 skrev Sverre Moe følgende:

 The groovy script executed by Groovy Postbuild does not run on Matrix 
 parent if this Post build publisher comes from a template project.
 There is an issue for this: 
 https://issues.jenkins-ci.org/browse/JENKINS-27317

 I order for the script to run on my several hundred jobs I would have to 
 duplicate this script under each job. Maintenance would be a nightmare.

 Thankfully Execute System Groovy script could load the script from a file, 
 thus I solve my script duplication problem. It exposes some of the same 
 variables as Groovy Postbuild, such as the current build. However I cannot 
 get the script to run only on Matrix parent

 Build - Execute System Groovy script - Script command
 import hudson.matrix.MatrixBuild;
 import hudson.matrix.MatrixRun;

 if (build instanceof MatrixRun) {
   println MatrixRun child 
 } else if (build instanceof MatrixBuild) {
   println MatrixBuild parent 
 }
 It seems it only runs on each matrix build configurations (childs).


-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/7066c141-1e76-46e3-87f6-8774992b6ec3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Project doBuild with Stapler

2015-03-17 Thread Sverre Moe
Thank you for that. Difficult to find out these things by just reading the 
API.

tirsdag 17. mars 2015 10.39.58 UTC+1 skrev Daniel Beck følgende:

 These functions are not supposed to be called directly, they clearly 
 handle HTTP requests. 

 Just call scheduleBuild2 and use the returned QueueTaskFuture. 

 On 17.03.2015, at 10:34, Sverre Moe sverr...@gmail.com javascript: 
 wrote: 

  Trying to call doBuild on a project in Groovy. I cannot find any 
 examples on how to use this method when it comes down to StaplerRequest and 
 StaplerResponse. 
  
  I am tempted to just call newBuild(), but I guess that would not get me 
 a hook into that build process/result. 
  
  I am iterating through a list of downstream projects: 
  For each downstream project, call doBuild. 
  The upstream project should wait, probably with 
 project.setBlockBuildWhenDownstreamBuilding(true) 
  If downstream project fails, then fail upstream project 
  
  Using Groovy Postbuild 2.2 with latest Jenkins 1.604 
  
  -- 
  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 javascript:. 
  To view this discussion on the web visit 
 https://groups.google.com/d/msgid/jenkinsci-dev/d882fbc5-35dc-4642-aaaf-6d0e2c5b013f%40googlegroups.com.
  

  For more options, visit https://groups.google.com/d/optout. 



-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/e814c6e9-7e39-4cd8-9f22-cb2b9ed60eef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Project doBuild with Stapler

2015-03-17 Thread Sverre Moe
Trying to call doBuild on a project in Groovy. I cannot find any examples 
on how to use this method when it comes down to StaplerRequest and 
StaplerResponse.

I am tempted to just call newBuild(), but I guess that would not get me a 
hook into that build process/result.

I am iterating through a list of downstream projects:
For each downstream project, call doBuild. 
The upstream project should wait, probably 
with project.setBlockBuildWhenDownstreamBuilding(true)
If downstream project fails, then fail upstream project

Using Groovy Postbuild 2.2 with latest Jenkins 1.604

-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/d882fbc5-35dc-4642-aaaf-6d0e2c5b013f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Groovy Postbuild: Run script only on matrix parent

2015-03-10 Thread Sverre Moe
Would it possible to have Groovy Postbuild to the script only run on matrix 
parent? Would be a great feature to get in this plugin.

I have a groovy script I want to run once after all matrix configurations 
have been triggered and completed.

I need to check the Cause not being an UpstreamCause, but all matrix builds 
Cause are of class UpstreamCause, while the parent Cause could be Upstream, 
UserId or SCM.

Created a feature request in Jenkins Jira:
https://issues.jenkins-ci.org/browse/JENKINS-27317

-- 
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-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/f6230b1f-c032-4646-a9f5-5cd78a27c3e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.