I set a system message in our Jenkins application that is shown on all the pages that tells folks what the staging and production branches are.
<h3>
Jenkins v2.263.1
</h3>
<h4>
<ul>
<li>Production branch: release/3.2.1/li>
<li>Staging branch: release/3.4.0</li>
</ul>
</h4>
However, I manually have to set these in the system configuration page every time we update the branches. I do store these values in global variables in the system configuration page, so
production_branch = release/3.2.1
staging_branch = release/3.4.0
Can I use a Jenkins API to get these values so they are set automatically when the variables are updated, which I do via pipeline job? Something like (pseudo html)
<h3>
Jenkins v2.263.1
</h3>
<h4>
<ul>
<li>Production branch: curl https://myjenkins.company.com/.../request_uri$production_branch</li>
<li>Staging branch: curl https://myjenkins.company.com/.../request_uri$staging_branch</li>
</ul>
</h4>
Note that I'm also exploring the ideas in Way to remotely update Jenkins "System Message" string?
Related
User needs the ability to perform particular action in Jenkins UI on any of the job builds that are already finished with access to the build`s ID.
For each build in history there is menu with items "Changes", "Console output", "Delete build", "Rebuild" etc. Can I add a custom command into that menu using an existing plugin? The command will be "pass build ID to a script on Jenkins machine and launch the script" or at least "put build ID to a file" or "pass build ID to another job and launch it".
Is there any plugin that can do that?
The workarounds I am currently aware of are the following:
a separate Jenkins job that gets required build ID (needs launching another job, correct copying of the build ID)
rename build using menu item "Edit Build Information", then a script/cron job on Jenkins machine will do what it needs to (requires correct renaming)
putting a link to script into html report
artifact an html with the link to script
Looked at the plugins like "batch-task", "sidebar-link" etc., but all work on job level and not on build level.
P.S. It is a free-style Jenkins job, pipeline / Groovy has not been used.
Perhaps a Groovy script might help? How can it look like and how to make launching such script user-friendly (ideally with one button)?
When I run a script in jenkins the following error is displayed:
Started by user *********
Running in Durability level: MAX_SURVIVABILITY
java.lang.NoClassDefFoundError: Could not initialize class org.jenkinsci.plugins.workflow.cps.CpsThread
at org.jenkinsci.plugins.workflow.cps.CpsScript.<init>(CpsScript.java:69)
at WorkflowScript.<init>(WorkflowScript)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.codehaus.groovy.runtime.InvokerHelper.createScript(InvokerHelper.java:434)
at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:133)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:126)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:561)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:522)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:320)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
Finished: FAILURE
I can't figure out which plugin is missing or which version is incorrect.
Java version 2.176.1
Ant Plugin 1.9 <br>
Apache HttpComponents Client 4.x API Plugin 4.5.5-3.0 <br>
Authentication Tokens API Plugin 1.3 <br>
Backup plugin 1.6.1 <br>
bouncycastle API Plugin 2.17 <br>
Branch API Plugin 2.5.2 <br>
Build Monitor View 1.12 <br>
Build Timeout 1.19 <br>
buildgraph-view 1.8 <br>
built-on-column 1.1 <br>
Command Agent Launcher Plugin 1.3 <br>
Conditional BuildStep 1.3.6 <br>
Config File Provider Plugin 3.6.2 <br>
Copy data to workspace plugin 1.0 <br>
Credentials Binding Plugin 1.19 <br>
Credentials Plugin 2.2.0 <br>
Cucumber reports 4.8.0 <br>
Cucumber Trend Reports 1.3 <br>
Display URL API 2.3.1 <br>
Docker Commons Plugin 1.15 <br>
Docker Pipeline 1.18 <br>
Durable Task Plugin 1.29 <br>
Email Extension Plugin 2.66 <br>
EnvInject API Plugin 1.5 <br>
Environment Injector Plugin 2.1.6 <br>
External Monitor Job Type Plugin 1.7 <br>
File System SCM Plugin 2.1 <br>
Folders Plugin 6.9 <br>
Git client plugin 2.8.0 <br>
Git plugin 3.10.1 <br>
GIT server Plugin 1.7 <br>
GitHub API Plugin 1.95 <br>
GitHub Authentication plugin 0.32 <br>
GitHub Branch Source Plugin 2.5.3 <br>
GitHub Organization Folder Plugin 1.6 <br>
GitHub plugin 1.29.4 <br>
Gitlab Authentication plugin 1.4 <br>
GitLab Plugin 1.5.12 <br>
Gradle Plugin 1.33 <br>
Green Balls 1.15 <br>
Groovy 2.2 <br>
HP Operations Orchestration Automation Execution Plugin 2.1.1 <br>
Icon Shim Plugin 2.0.3 <br>
Jackson 2 API Plugin 2.9.9 <br>
Javadoc Plugin 1.5 <br>
JavaScript GUI Lib: ACE Editor bundle plugin 1.1 <br>
JavaScript GUI Lib: Handlebars bundle plugin 1.1.1 <br>
JavaScript GUI Lib: jQuery bundles (jQuery and jQuery UI) plugin 1.2.1 <br>
JavaScript GUI Lib: Moment.js bundle plugin 1.1.1 <br>
JavaScript GUI Lib: Twitter Bootstrap bundle plugin 1.3.2 <br>
JDK Tool Plugin 1.2 <br>
jQuery plugin 1.12.4-0 <br>
jQuery UI plugin 1.0.2 <br>
JSch dependency plugin 0.1.55 <br>
JUnit Plugin 1.28 <br>
LDAP Plugin 1.20 <br>
Lockable Resources plugin 2.5 <br>
Mailer Plugin 1.23 <br>
MapDB API Plugin 1.0.9.0 <br>
Matrix Authorization Strategy Plugin 2.4.2 <br>
Matrix Project Plugin 1.14 <br>
Maven Integration plugin 3.3 <br>
Micro Focus Application Automation Tools 5.8 <br>
Multijob plugin 1.32 <br>
OWASP Markup Formatter Plugin 1.5 <br>
PAM Authentication plugin 1.5.1 <br>
Parameterized Scheduler 0.6.3 <br>
Parameterized Trigger plugin 2.35.2 <br>
Periodic Backup 1.5 <br>
Pipeline 2.6 <br>
Pipeline Aggregator 1.8 <br>
Pipeline Graph Analysis Plugin 1.10 <br>
Pipeline: API 2.35 <br>
Pipeline: Basic Steps 2.18 <br>
Pipeline: Build Step 2.9 <br>
Pipeline: Declarative 1.3.9 <br>
Pipeline: Declarative Agent API 1.1.1 <br>
Pipeline: Declarative Extension Points API 1.3.9 <br>
Pipeline: GitHub Groovy Libraries 1.0 <br>
Pipeline: Groovy 2.70 <br>
Pipeline: Input Step 2.10 <br>
Pipeline: Job 2.33 <br>
Pipeline: Milestone Step 1.3.1 <br>
Pipeline: Model API 1.3.9 <br>
Pipeline: Multibranch 2.21 <br>
Pipeline: Multibranch with defaults 1.1 <br>
Pipeline: Nodes and Processes 2.31 <br>
Pipeline: REST API Plugin 2.11 <br>
Pipeline: SCM Step 2.9 <br>
Pipeline: Shared Groovy Libraries 2.13 <br>
Pipeline: Stage Step 2.3 <br>
Pipeline: Stage Tags Metadata 1.3.9 <br>
Pipeline: Stage View Plugin 2.11 <br>
Pipeline: Step API 2.20 <br>
Pipeline: Supporting APIs 3.3 <br>
Plain Credentials Plugin 1.5 <br>
PowerShell plugin 1.3 <br>
promoted builds plugin 3.3 <br>
Resource Disposer Plugin 0.12 <br>
Role-based Authorization Strategy 2.13 <br>
Run Condition Plugin 1.2 <br>
Safe Restart Plugin 0.3 <br>
SCM API Plugin 2.6.3 <br>
Script Security Plugin 1.61 <br>
Shared Workspace 1.0.2 <br>
SSH Agent Plugin 1.17 <br>
SSH Credentials Plugin 1.17.1 <br>
SSH plugin 2.6.1 <br>
SSH Slaves plugin 1.30.0 <br>
Structs Plugin 1.19 <br>
Subversion Plug-in 2.12.2 <br>
SVN 1.3 Compatibility Plugin 1.2 <br>
SVN 1.4 Compatibility Plugin 1.1 <br>
Timestamper 1.10 <br>
Token Macro Plugin 2.8 <br>
WMI Windows Agents Plugin 1.4 <br>
The only thing I found is that it's hard to diagnose and the following steps might help you recover
Manually remove the workflow packages from JENKINS_HOME/plugins
Upgrading all plugins.
Restarting jenkins.
Download the workflow plugins, and set to install on restart.
Then it was working fine.
You might need to specify "node" you are running your pipeline stage on :
node('my_slave') {
stage('my_stage') {
// do fancy code
}
}
Regards
I am using Jenkins to automate our build and release process.
In that I am using "List Subversion tags (and more)" parameter and hardcoded my project SVN URL in the "Repository URL" filed (Refer below Screentshot). That lists the branches of my project.
In that repository URL field, the host name of the server "svnserver" may be changed in future and it is used in 400+ jobs in Jenkins. Hence, I have created a enivironment variable in Jenkins configuration page and used in the field as follows.
But it is not working. Thats, the branches are not listed in the parameter as follows.
How to use environment variable in "List Subversion tags (and more)" parameter in Jenkins?
Currently my workflow is using jenkins with multibranch-pipeline (declarative pipeline/jenkinsfile) to checkout from SVN, build, test with sonarqube and deploy to a weblogic server, it's working fine with all the branches needed.
Jenkins is configured to use active directory/ldap to enable all my colleagues to login with their credentials
I just don't know how to get all the emails from the users who did commit since the last build, as i want to send them an email (go and fix <3)
I'm kinda new to jenkins and i'm findind difficult to find some good documentation, thanks in advance for any help!
Figured it out
With active directory enabled, jenkins already knows everything i need and i can just use this code inside the post{} section of the declarative pipeline
failure {
script {
def emails= []
emails << emailextrecipients([[$class: 'CulpritsRecipientProvider']])
emails = emails.join(',')
emailext to: emails, subject:"JENKINS - ${currentBuild.fullDisplayName} - ${currentBuild.currentResult}", body: "Check out what you have done, jenkins is crying!!!"
}
}
We want to use Jenkins to generate releases/deployments on specific project milestones. Is it possible to trigger a Jenkins Pipeline (defined in a Jenkinsfile or Groovy script) when a tag is pushed to a Git repository?
We host a private Gitlab server, so Github solutions are not applicable to our case.
This is currently something that is sorely lacking in the pipeline / multibranch workflow. See a ticket around this here: https://issues.jenkins-ci.org/browse/JENKINS-34395
If you're not opposed to using release branches instead of tags, you might find that to be easier. For example, if you decided that all branches that start with release- are to be treated as "release branches", you can go...
if( env.BRANCH_NAME.startsWith("release-") ) {
// groovy code on release goes here
}
And if you need to use the name that comes after release-, such as release-10.1 turning into 10.1, just create a variable like so...
if( env.BRANCH_NAME.startsWith("release-") ) {
def releaseName = env.BRANCH_NAME.drop(8)
}
Both of these will probably require some method whitelisting in order to be functional.
I had the same desire and rolled my own, maybe not pretty but it worked...
In your pipeline job, mark that "This project is parameterized" and add a parameter for your tag. Then in the pipeline script checkout the tag if it is present.
Create a freestyle job that runs a script to:
Checkout
Run git describe --tags --abbrev=0 to get the latest tag.
Check that tag against a running list of builds (like in a file).
If the build hasn't occurred, trigger the pipeline job via a url passing your tag as a parameter (in your pipeline job under "Build Triggers" set "Trigger builds remotely (e.g. from scripts) and it will show the correct url.
Add the tag to your running list of builds so it doesn't get triggered again.
Have this job run frequently.
if you use multibranch pipeline, there is a discover tag. Use that plus Spencer solution