Jenkins Build With Parameters shows old and new parameter fields - jenkins

My Jenkins shared pipeline, used by dozens of repos internally, has several parameter fields defined. We have several repos that initially used another library, or their own ad-hoc pipelines, but then imported the shared library.
In some of these cases, the "Build With Parameters" UI shows both the old and new parameters. We have re-run the pipelines several times, but the old fields won't go away.
If we create a new branch, only the new fields are shown.
I am thinking there's an xml file on the controller that we have to wipe, but I'm not sure where.
Has anyone seen this? What's the resolution?
Update 1
I went into the jobs folder for a branch showing this, and backed-up the config.xml file:
> cd /mnt/data/jenkins/jobs/<org>/jobs/workflows/jobs/<repo>/branches/jenkins-test/
> mv config.xml config.xml-bak
Upon re-running the job, it re-creates the config.xml and it has the same issue: old and new fields still showing.
So I deleted the entire jenkins-test branch folder. The job doesn't go away in the UI. I made a test commit to the branch in Github, Jenkins picked it up and ran it. It automatically re-created the jenkins-test folder on the controller, and upon re-trying Build With Parameters, it still shows the old and new params.
Got to keep digging...
Update 2
I created https://issues.jenkins.io/browse/JENKINS-69652 for this.
update 3
I confirmed the commit that triggered the build is the right commit in the source repo, and it is pulling the correct commit of the pipeline library.
Update 4
Interesting. I Replayed a run, and entered a dummy pipeline:
pipeline {
agent none
stages {
stage ('hello') {
steps {
echo 'hello!'
}
}
}
}
Going back to the Build With Parameters UI, it now shows only the old parameter fields. Where is this coming from? Where is it stuck??

My first guess is that you're loading a Pipeline library implicitly and defining the parameters in that implicitly loaded Pipeline library.
Pipeline libraries that are loaded implicitly are loaded into the Jenkinsfile without requiring an #Library reference to load them.
Check the jobs and the parent folders of those jobs and the root for Pipeline libraries that are defined and have the 'Load implicitly" checkbox enabled.

Related

Using text editor for configuring Jenkins job's UI elements

Is it possible to edit/save the code of "Job Configuration" (the structure and order of UI elements) ?
The pipeline job get the pipeline code from git, but this occurs only AFTER the job started. I want to edit the UI of job parameters (BEFORE user press "build")
Its necessary for 2 reasons :
its much easier to cut/paste text lines, than move elements up/down with the mouse.
can be saved and deployed easily on a new Jenkins machine
You can edit the configuration before the job is run to add the initial build parameters. If you then have the build parameters also defined in the pipeline, the parameters will be overwritten with the ones defined in the pipeline.
However, for that first build, if the build parameters defined in the job configuration and the ones in the pipeline match, the build parameter values will be used in that initial run.

No Save/Apply button on Jenkins pipeline configuration page

The Save/Apply button is missing from Jenkins pipeline configuration page. There seems to be no other way to apply changes to the configuration settings. I am unable to find any useful answers or workarounds as well. I have tried several Javascript workarounds, reinstallation, uninstalled plugins that generated warnings, and stuff but nothing seems to be working. I am using Jenkins version 2.222.3 with BlueOcean.
It would be a great help if anyone can suggest a solution.
Jenkins Pipeline configuration is defined in Jenkins Pipeline (e.g. Jenkinsfile). To change your configuration, you need to edit your Jenkinsfile.
E.g. to change "Build periodically", here's an example of edit you need to do:
pipeline {
triggers {
cron('* * * * *') // run every minute
This is why the page you're looking at is called "View Configuration" — it is for viewing only.
Using the GitHub plugin, we have an organization folder that is scanned for any repositories that contain a Jenkinsfile. The configuration you are viewing is driven by a config.xml that is copied from the organization folder into each job that runs in a repo. So you want your changes to affect jobs/my_organization/config.xml, not jobs/my_organization/jobs/my_repo/config.xml.
In the UI this is accomplished by going up a level or two from the job or job run. There you will see the link change from "View Configuration" to "Configure".

How can I have different configuration for the job and one of it's run

I configured a job on Jenkins which trigger some script in python and does some tests. In the end, it gives results inside an artifact folder (so we can keep X amount of results at any time), which I am showing presenting with a Publish rich text message post-build action. Here is the pretty straight forward code:
<br/>
<h2>Results:</h2>
<iframe src=./artifact/artifacts/results.html width=1100 height=1000></iframe>
This works correctly inside a job build, but if you go inside the main page of the job, I get a 404 not found since it cannot find the file. I understand that the error is correct, since it cannot find any artifact folder if we are not within a build of the said job. My question is how can I have different settings depending if we are inside the main page of the job vs a build of the job ?
I checked online and found that there is a lastSuccessfulBuild variable I can use but then I think it will show the same results no matter which build we are, which is something I do not want.

Jenkins pipeline menu does not show the "Configure", "Build Now", and some other options

I have a Jenkins pipeline that I have setup with a project I have on GitHub. Initially, I manually initiated a build each time I changed my code by clicking the "Build Now" option. However, I did two things to make my process easier:
I setup a GitHub hook to run the build I defined in my Jenkinsfile after each push to my master branch
I setup a periodic build to build every hour
I left my Jenkins for a day, came back, and everything, even from the dashboard, looks different.
For example:
My dashboard used to have these options:
New Item
People
Build History
Project Relationship
Check File Fingerprint
Manage Jenkins
My Views
Lockable Resources
Credentials
New View
The current dashboard only has three of those options:
People
Build History
Credentials
Also, when I clicked on my pipeline, the options I had were:
Status
Changes
Build Now
Delete Pipeline
Configure
Full Stage View
Rename
Pipeline Syntax
Whereas now, they are:
Status
Full Stage View
GitHub Hook Log
Git Polling Log
How can I change my configurations/settings to see the pages the way I saw them before? It seems I can't create any new items or change my current pipeline, which are things I may need to do in the future.
It turns out I wasn't logged in. I didn't think the initial pages would even show up if I hadn't been logged in, so I didn't even consider it to be a possibility. I logged in and all my issues were resolved.

How to instruct Jenkins to look for email template in user defined path (OTHER THAN $JENKINS_HOME/email-templates)

I have groovy email template(for Selenium Robot framework test execution) for Jenkins. Jenkins master is controlled by a remote team. So for placing this template in $JENKINS_HOME/email-templates, we need to raise a ticket and wait from 2 to 3 days. Also we expect, there might be changes required in template. So we are planning to put our templates inside our source code repository (GIT). so in the Jenkins test job, we checkout the test script together with email templates.
How to instruct Jenkins to look for the template in workspace folder instead of $JENKINS_HOME/email-templates in Jenkins Master
Sadly it seems you would need to modify the email-ext plugin as the search path is hardcoded into it.
You can see it here, check the occurrence on line 69 in file src/main/java/hudson/plugins/emailext/EmailExtTemplateAction.java
Changing it to another path would be trivial, however adding multiple locations you'd probably have to put some work in.
Edit: I wonder if it would be possible to put the wanted stuff into some txt file as a build step, and then load it into the mail content via some template configuration. If you have access to the job configuration this might be worth checking.
You can copy the template into the build workspace (e.g. with SCM step), and then email-ext can reach it:
${SCRIPT, template="${WORKSPACE}/foo.template"}

Resources