Re: Anyway to programatically update a Jenkinsfile?

2019-10-03 Thread Tim Black
I have to agree with Jeremy on this. Using a templating engine like m4 or 
jinja2 is superior to programmatic generation of groovy, if you need to do 
it on the fly. Why? Simplicity and Readability.

I inherited a build system that is based on using a multibranch pipeline 
with a Jenkinsfile that loads and executes a groovy script that's generated 
on the fly based on input from structured data from json files found 
alongside the Jenkinsfile in the repo. So, yeah, it's basically a 
hand-rolled solution to parametrizing a job. It sounds like that's 
basically what you're trying to accomplish as well, Jeff.

The part I don't like is the way we're generating the groovy code. We've a 
library of python code that uses classes and a streaming approach to 
outputting all the syntax required to implement the pipeline. First of all, 
there's a high learning curve to using this approach - when trying to 
determine what the groovy output will look like you have to run the code 
and look at the output, which is a whole software development process in 
and of itself. When making changes, instead of using a template with 
variable substitution and loops perhaps, with the programatic approach, you 
have to write (and test and debug) code to make the groovy code you want. A 
template already resembles what the final output (groovy) will look like, 
so it's quite intuitive to work on. Also, every time you need to use a new 
groovy construct, with the programatic approach, you have to add support 
for it in your code gen library. With the template you just write it, based 
on the pipeline syntax documents. This brings up another reason why 
templated approach is superior: Programatic approach obfuscates the details 
of the language  from the code gen developer. Looking back and forth 
between the jenkins pipeline syntax docs and a template is straightforward, 
not so with a library of classes defined to generate groovy.

So, that's my $0.02. I plan to refactor our code gen library to use jinja2 
templating to make our pipelines more intuitive and easier to work with.

Another thing related to keep in mind is that, as far as I can tell, the 
"load" command, which is the mechanism you would use to actually run your 
generated pipeline script, is designed to work with Scripted Pipeline, not 
Declarative. This distinction is very poorly documented by Cloudbees, IMO. 
Please chime in if you have more info on dynamic generation and running of 
pipeline code.

On Tuesday, October 1, 2019 at 8:43:25 AM UTC-7, Jeff Sault wrote:
>
> Does anyone know of any libraries/tools that will allow me to 
> add/remove/update sections of a Jenkinsfile programatically? I have a load 
> of different projects which I need to update to include some new mandatory 
> parameters. I'd like to go down the 'shared library' route but in this 
> instance its not really possible. Parsing the jenkinsfile is non-trivial 
> but I assume theres something in groovy/jenkins land which can already do 
> the job.
>
> Thanks
> Jeff
>

-- 
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/d77f7156-b8b9-4b65-9959-1aad8a39f2a5%40googlegroups.com.


stash/unstash file size limit and performance

2019-10-03 Thread Tim Black
The Jenkins documentation for the stash pipeline step 

 
says that it's only to be used for "small files", with no explanation why.

Specifically, how is stash bad for large, i.e. not small files? How should 
we define "not small"? 

What's the deal, is it just a slow transfer, or is it buggy?? Just curious 
why I shouldn't stash a 150MB file on a master so I can unstash it from a 
slave agent in a subsequent stage. Seems much simpler than using External 
Workspace Manager which is what they recommend for everything but "small 
files".

-- 
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/7a5c2a40-7853-4b5a-aaa8-f9ac5ca94485%40googlegroups.com.


problems changing triggers{} in multibranch pipeline Jenkinsfile

2019-10-03 Thread Tim Black
We have a multibranch pipeline job set up to scan a git repo (which 
contains Jenkinsfile at its root) for branches and create branch-specific 
jobs for each branch discovered. The Jenkinsfile on a branch specifies:

triggers {
cron('@midnight')
}

and this indeed runs nightly at midnight. However, when I delete the above 
block and commit the Jenkinsfile to my branch, it appears to have no 
effect. Last night the build still ran at midnight. This is my problem.

I confirmed the change by looking on the branch job configuration page and 
indeed see an empty BuildTriggers section. There are no triggers specified 
and none of the trigger checkboxes are checked.

Please confirm whether this is indeed the way I am supposed to disable a 
trigger specified in a multibranch pipeline Jenkinsfile. 

Also, note that in the top-level pipeline job configuration, BranchSources 
is set up so "All branches get same properties" and set the property 
"Suppress Automatic SCM Triggering" because we only want builds to be done 
nightly for now, and not as a result of commits. Also, "Scan Multibranch 
Pipeline Triggers" is configured to scan our repo every minute for branch 
changes. I assume this means that it also scans and applies any changes to 
Jenkinsfiles (e.g. our trigger {} changes) to the branch job. I believe 
this to be happening, bc as I've said, the job configuration page seems to 
have reflected our change to the Jenkinsfile in SCM. But the build still 
was triggered last night at midnight.

Please let me know if you know what's going wrong here, or have any 
suggestions for troubleshooting this.

Thanks,
Tim

-- 
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/37a06f44-fa92-4970-b9f5-0f32f069f609%40googlegroups.com.


Re: Clean useless files and directories

2019-10-03 Thread ZillaYT
You mean multi-branch "pipeline" jobs? In the job config page, Orphaned 
Strategy section, you check the "Discard old items" check box.

On Monday, September 30, 2019 at 11:18:13 AM UTC-4, Peter Flanagan wrote:
>
> Hello,
> working on Jenkins 2.150 hosted on on AWS-EC2, jenkins_home dir is located 
> on an EFS
>
> The space of some Jenkins instances increase dramatically due to folder 
> not removed automatically by internal Jenkins storage management.
>
> Using multi-branch jobs I got 2 major issues:
> - some branches directories stay on file system despite the branches does 
> not exist anymore on GUI
> - some workspace__* directories stay also on FS despite the build 
> workspace always linked to the last waorkspace (without __ suffix)
>
> I'm wondering how to clean these two useless (according to me) directories 
> properly.
>
> Thanks very much for your help  
>

-- 
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/f822f0aa-f1bd-4701-a696-9680cce90798%40googlegroups.com.


Re: Ansible Playbook using Jenkins

2019-10-03 Thread ZillaYT
There's a nice Ansible plugin for Jenkins

On Tuesday, September 24, 2019 at 9:32:02 AM UTC-4, Vikrant Kaushik wrote:
>
> Hi All,
>
> Can anybody advise how to run Ansible playbook using Jenkins if we have 
> any relevant link available?
>
> regards
>
> Vikrant
>

-- 
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/c26ad885-5e99-46ba-8ea4-64322ba65c28%40googlegroups.com.


Re: 'Include' a shared library pipeline in other pipelines in the same shared library

2019-10-03 Thread ZillaYT
I'm guessing you've looked at this already 
https://jenkins.io/blog/2017/10/02/pipeline-templates-with-shared-libraries/
 

On Monday, September 30, 2019 at 3:35:30 AM UTC-4, Kaliyug Antagonist wrote:
>
> I have several microservices which use the same pipeline from a shared 
> library  which is 
> named *jenkins-shared-pipelines* . The Jenkinsfile for a microservice is 
> as follows:
>
> @Library(['jenkins-shared-pipelines']) _
>
> gradleProjectPrPipeline([buildAgent: 'oc-docker-jdk11', 
> disableIntegrationTestStage: true])
>
> In jenkins-shared-pipelines/vars, the gradleProjectBranchWrapper has the 
> following stages:
>
> /**
>  * gradleProjectPrPipeline is a generic pipeline
>  * @param pipelineProperties map used to pass parameters
>  * @return
>  */
> void call(Map pipelineProperties = [:]) {
> .
> .
> .
>
> pipeline {
> agent {
> node {
> label "${pipelineProperties.buildAgent}"
> }
> }
>
> options {
> skipDefaultCheckout true
> timeout(time: 1, unit: 'HOURS')
> buildDiscarder(logRotator(
> numToKeepStr: '5',
> daysToKeepStr: '7',
> artifactNumToKeepStr: '1',
> artifactDaysToKeepStr: '7'
> ))
> }
>
> stages {
> stage('Clone') {
> steps {
> //clone step
> }
> }
> stage('Compile') {
> steps {
> script {
>/*Some custom logic*/
> }
> runGradleTask([task: 'assemble',
>rawArgs: defaultGradleArgs + " 
> -Pcurrent_version=${releaseTag}"
> ])
> }
> }
> stage('Tests') {
> parallel {
> stage('Unit tests') {
> steps {
> //Unit tests
> }
> }
> stage('Integration tests') {
> steps {
> //Integration tests
> }
> }
> }
> }
> stage('Sonar scan') {
> steps {
> //Sonar scanning
> }
> }
> }
>
> post {
>
> unsuccessful {
> script {
> bitbucketHandler.notifyBuildFail([
> displayName: pipelineName,
> displayMessage: "Build ${env.BUILD_ID} failed at 
> ${env.BUILD_TIMESTAMP}."
> ])
> }
> }
> success {
> script {
> bitbucketHandler.notifyBuildSuccess([
> displayName: pipelineName,
> displayMessage: "Build ${env.BUILD_ID} completed at 
> ${env.BUILD_TIMESTAMP}."
> ])
> }
> }
> }
> }
> }
>
> Now, there will be several more pipelines in 
> jenkins-shared-pipelines(under the same vars directory) e.g: awsPipeline, 
> azurePipeline and so on which will also incorporate the deployment stages. 
> These pipelines will require all the stages in the above 
> gradleProjectBranchWrapper and will also add a few of their own stages. 
> Currently, we simply copy-paste these stages in the new pipelines, then, we 
> invoke these new pipelines from the microservices, so for example:
>
> @Library(['jenkins-shared-pipelines']) _
>
> awsPipeline([buildAgent: 'oc-docker-jdk11', disableIntegrationTestStage: 
> true])
>
> I was wondering if there is a way to include the 
> gradleProjectBranchWrapper in the pipelines like awsPipeline, azurePipeline 
> and so on. Note: There is a post block in the gradleProjectBranchWrapper, 
> the other pipelines may have their own post blocks
>

-- 
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/91afcbdf-0f44-420b-9152-19d2bc012937%40googlegroups.com.


Re: Triggering multi Pipeline Job after other multi job is executed

2019-10-03 Thread ZillaYT
That's how you do it.

On Thursday, October 3, 2019 at 6:46:52 AM UTC-4, Ramesh R wrote:
>
> Hi All,
>
> Please help me with this Problem.
>
> I want to RUN or Build Project B after Project A is Build or Stable.
>
> In Freestyle project we have option to Build after other projects are 
> built in Build Triggers.
>
> In Multi pipeline job, under Branch View configuration we have same 
> options, But no Save or Apply button.
>
> Is there any way to do it? or add Triggers in Jenkinsfile.
>
> Kindly let me know.
>
> Thanks,
> Ramesh
>

-- 
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/90ddb3f3-9605-48cb-8b1d-82ec6c17c788%40googlegroups.com.


Sharing code via shared library?

2019-10-03 Thread ZillaYT
I posted In a Jenkins shared library infrastructure, how do I import class 
in another file? 

 in 
Stackoverflow. Anyone here know if what I want to achieve is possible? If 
so how?

Thanks,
Chris

-- 
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/61a29be1-5e3f-4850-ae43-0e5dc5c343c5%40googlegroups.com.


Why Jenkins is keep removing workspaces folder on slave Nodes in 30 days. I have not configured any setting for this ?

2019-10-03 Thread Pranav Kumar
Jenkins is deleting workspaces on slave machines after 30 days. After 
looking into jenkins folder located at 
/var/lib/jenkins/logs/tasks

 I found logs here with name Workspace\ clean-up.log. Why this is being 
created?, I suspect it may be because of 
https://wiki.jenkins.io/display/JENKINS/Workspace+Cleanup+Plugin plugin. 
Now I have deleted this plugin as well. I have already looked at all 
possible configuration in Jenkins and Nodes, In my opinion there is no suc 
configuration that is causing this. Please suggest me why this behaviour is 
being shown by Jenkins?

-- 
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/b7e8eecc-7c2f-45d3-9e4c-273efb84b830%40googlegroups.com.


Re: Triggering multi Pipeline Job after other multi job is executed

2019-10-03 Thread Jan Monterrubio
I’ve done something similar with the build step, as a downstream job.

https://jenkins.io/doc/pipeline/steps/pipeline-build-step/


On Thu, Oct 3, 2019 at 05:46 Ramesh R  wrote:

> Hi All,
>
> Please help me with this Problem.
>
> I want to RUN or Build Project B after Project A is Build or Stable.
>
> In Freestyle project we have option to Build after other projects are
> built in Build Triggers.
>
> In Multi pipeline job, under Branch View configuration we have same
> options, But no Save or Apply button.
>
> Is there any way to do it? or add Triggers in Jenkinsfile.
>
> Kindly let me know.
>
> Thanks,
> Ramesh
>
> --
> 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/8a76afab-4771-476e-b548-4aba72958ba9%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/CADgiF9JL6CgrO%2BfOjThjK_hXD_0REQ03JTfBo%3D1bkCFKBqv5KA%40mail.gmail.com.