Re: Automating the Choice Parameter on a job

2020-10-22 Thread Danny Trunk
Hello Kari

As far as I know JsonSlurper isn't Serializable and defining it for re-use
will raise a NotSerializableException and this end up in the catch block.

You could either move the Code insider a @NonCPS annotated method or doing
everything in one statement.

Kari Cowan  schrieb am Do., 22. Okt. 2020, 23:25:

> I couldn't get that to work right but got a little but further using the
> JsonSlurper (as opposed to JsonSlurperClassic)
>
> Assuming my data structure is represented in json like:
>
> {
>   "name": "templates",
>   "tags": [
> "qa_tmpl-92",
> "qa_tmpl-93",
> "qa_tmpl-94"
>   ]
> }
>
> I was trying something like this:
>
> import groovy.json.JsonSlurper
> try {
> List artifacts = new ArrayList()
> def artifactsUrl = "http://localhost:5000/v2/templates/tags/list";
>
> def artifactsObjectRaw = ["curl", "-s", "-H", "accept:
> application/json", "-k", "--url", "${artifactsUrl}"].execute().tags
> def jsonSlurper = new JsonSlurper()
> def artifactsJsonObject = jsonSlurper.parseText(artifactsObjectRaw)
> def dataArray = artifactsJsonObject.data
> for(item in dataArray){
> if (item.isMetadata== false)
> artifacts.add(item.tags)
> }
> return artifacts
> } catch (Exception e) {
> print "There was a problem fetching the artifacts"
> }
>
> Running in groovysh, it didn't show me an error, but I ended up in the
> catch, so I think the way I am trying to do curl, this bit in particular
> (${artifactsUrl}"].execute().tags) is wrong.
>
> There was a problem fetching the artifacts ===> null
>
>
> Can anyone point me in the right direction here?
>
> On Mon, Oct 19, 2020 at 5:07 PM Kari Cowan  wrote:
>
>> Nice. That’s a good tip. Thanks 😊
>>
>> On Mon, Oct 19, 2020 at 4:36 PM Jan Monterrubio 
>> wrote:
>>
>>> Yep, if docker tags can return you json, you can just slurp stuff and
>>> transform it.
>>>
>>> On Mon, Oct 19, 2020 at 09:27 Kari Cowan  wrote:
>>>
 This is clever - thanks.

 I don't have a directory of files in my git project- but I am guessing
 I could write something to add - like a deployment tag list that matches
 the docker registry?

 Ideally I would pull the docker register tag list and use that.


 On Fri, Oct 16, 2020 at 1:15 PM janmont...@gmail.com <
 janmonterru...@gmail.com> wrote:

>  import groovy.json.JsonSlurperClassic
>  def jsonSlurper = new JsonSlurperClassic()
> def response = jsonSlurper.parse(new URL("SOME REPO HERE"))
> return response
>
> It was something like that ^
>
> You can always start with a "return [ 'a', 'b'] " , we used the
> ActiveChoice reactive parameter
>
>
> On Thursday, October 15, 2020 at 11:32:33 PM UTC-5
> janmont...@gmail.com wrote:
>
>> I’ve used the extended choice parameter to pull a list of files from
>> a directory in github and display a set of checkboxes. I’ll remember to
>> grab you a snippet tomorrow during work!
>>
>>
>>
>> On Thu, Oct 15, 2020 at 17:01 Kari Cowan  wrote:
>>
>>> I am working on a Jenkins job to rollback a Docker container to the
>>> previous version.  This on its own is pretty straight-forward, but what 
>>> I
>>> want to do is get my list of available tags from the registry. As 
>>> opposed
>>> to going to the registry-page and seeing what's available, then 
>>> copy/paste
>>> a value into a form on Jenkins, I'd like to automate that step somehow 
>>> - by
>>> grabbing the data from the registry page and displaying the options in a
>>> choice parameter in Jenkins on the build screen.
>>>
>>> For example, call in the registry url by ip, example,
>>> 10.11.12.199:5000/v2/some-api/tags/list might display some JSON
>>> like:
>>> {"name":"some-api","tags":["qa_api-11","qa_api-12","qa_api-13"]}
>>>
>>> What's the best tool for this?  I'm no Groovy expert but would the
>>> Extensible Choice Parameter plugin coupled with a Groovy script be 
>>> useful
>>> here? I'm not really clued up yet if this is possible in Groovy, but am
>>> open to suggestions.  Does anyone have any tips on that or other methods
>>> that are better?
>>>
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Jenkins Users" group.
>>> To unsubscribe from this group and stop receiving emails from it,
>>> send an email to jenkinsci-use...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/jenkinsci-users/CAE7w4hg_RpwfVYAh7m9FLc1oxCPZQuqwd-eMpj6kFgBdMsJoOA%40mail.gmail.com
>>> 
>>> .
>>>
>> --
> You received this message because you are subscribed to the Google
> Groups "Jenki

Re: How to access jenkins using ip address remotely ?

2020-10-20 Thread Danny Trunk

Hello Vaibhav,

what does "remotely" mean? Inside your network or outside from the 
internet?

Inside of your network this should work out of the box.
Outside from the internet you need to open port 8080 to access it.
Please refer to the documentation of your router on how to open a port.
Keep in mind this might be a security issue.

And in addition: If you have 24h reconnect in order to get a new ip 
address you can get and run a so called DynDNS address.

There are several providers out there.
Some (or most?) routers support configuring a DynDNS address as well - 
so you don't have to run a service on your computer.


Am Mo, 19. Okt, 2020 um 10:22 NACHMITTAGS schrieb Vaibhav Khachane 
:

Hello Team,

I am trying to access jenkins using ip address but it is not working 
. I am using macOS.


Following jenkins url working fine




but while using ip adress of my machine it is not working
http://(ip address of my. machine ):8080/


 --
 You received this message because you are subscribed to the Google 
Groups "Jenkins Users" group.
 To unsubscribe from this group and stop receiving emails from it, 
send an email to jenkinsci-users+unsubscr...@googlegroups.com 
.
 To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/0a2be992-d850-41d8-a0eb-6959888f0cb0n%40googlegroups.com 
.


--
You received this message because you are subscribed to the Google Groups "Jenkins 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/JS8IIQ.Z02SEYIZGNFU2%40gmail.com.


Jenkins Console Output: declarative pipeline + sh + python line-buffered

2020-10-18 Thread Danny Trunk

Hello everybody,

I've set up a declarative pipeline job using the sh step to run repo 
(which is a tool written in python - more information: 
)

But I can't get stdout to be line-buffered.

I've already tried the following:
* `export PYTHONUNBUFFERED=1` in the sh block before calling repo.
* setting PYTHONUNBUFFERED=1 in the environment block
* using `stdbuf -i0 -e0 -o0 repo sync ...` instead of calling `repo 
sync ...` directly

* combined all of the above

I can't see any repo progress in the build console.

By running the command manually in a bash I'm getting this output:
```
root@jenkins-lineage:/var/jenkins_home/workspace/lineage# repo sync -j 
2 --force-sync

remote: Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
Fetching projects:   0% (1/774) LineageOS/android_artremote: Total 0 
(delta 0), reused 0 (delta 0), pack-reused 0
Fetching projects:   0% (2/774) LineageOS/androidremote: Total 0 (delta 
0), reused 0 (delta 0), pack-reused 0
Fetching projects:   0% (3/774) LineageOS/android_bionicremote: Total 0 
(delta 0), reused 0 (delta 0), pack-reused 0
Fetching projects:   0% (5/774) platform/build/katiremote: Total 0 
(delta 0), reused 0 (delta 0), pack-reused 0
Fetching projects:   0% (6/774) 
LineageOS/android_build_blueprintremote: Total 0 (delta 0), reused 0 
(delta 0), pack-reused 0
Fetching projects:   1% (10/774) platform/developers/build^Caborted by 
user

```

Here's an example of how I call repo:
```
sh """#!/bin/bash
repo init -u ${REPOSITORY_URL} -b ${params.BRANCH} --depth=1
repo sync -j ${params.SYNC_THREADS} --force-sync
"""
```

And here's the complete Jenkinsfile: 



So how I can get more information from repo in the Jenkins build 
console?


Danny.

--
You received this message because you are subscribed to the Google Groups "Jenkins 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/ODIEIQ.TBP9FP8IA0TP2%40gmail.com.


[JCasC] job parameters lost when re-starting docker container / reloading existing configuration

2020-10-16 Thread Danny Trunk

Hello everyone,

I've set up a container with jenkins.yaml file in $JENKINS_HOME which 
is loading a parameterized pipeline job:


jobs:
 - script: >
 pipelineJob('lineage') {
   definition {
 cpsScm {
   scriptPath 'Jenkinsfile'
   scm {
 git {
   configure { git ->
 git / 'extensions' / 
'hudson.plugins.git.extensions.impl.SparseCheckoutPaths' / 
'sparseCheckoutPaths' {
   
'hudson.plugins.git.extensions.impl.SparseCheckoutPath' {

 path('Jenkinsfile')
   }
 }
   }
   extensions {}
   remote {
 url 
''

   }
 }
   }
 }
   }
 }

In order to retrieve the parameters defined in the Jenkinsfile it needs 
to be initially run.
There's a known issue which described that behaviour: 



But now, everytime i restart the container or reload existing 
configuration through UI parameters are gone again and my workaround to 
abort the first build doesn't work anymore because it checks for the 
build number 1:


script {
	if ('1'.equals(env.BUILD_NUMBER) && 
currentBuild.getBuildCauses('hudson.model.Cause$UserIdCause') != null) {

currentBuild.displayName = 'Parameter loading'
currentBuild.description = 'Please restart pipeline'
currentBuild.result = 'ABORTED'

		error 'Stopping initial manually triggered build as we only want to 
get the parameters'

}
}

Any ideas on how I can extend my workaround or better how to avoid 
removing existing job parameters when reloading existing configuration?
I don't know if this can be considered a bug or an enhancement request 
for JCasC to not remove those job parameters.

Any help is appreciated.

Danny.

--
You received this message because you are subscribed to the Google Groups "Jenkins 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/WRZAIQ.I9W7CPAM6YSS%40gmail.com.