How do I show an URL in input description of Jenkins pipeline - jenkins

During the pipeline execution, I need to ask user whether to proceed the stage with below shown input options which is working fine. However thinking of enhancing the input message by converting the description of the input message to a clickable URL instead of plain text which is happening now.
environment {
def delobjectsurl = "${env.BUILD_URL}/artifact/logs/stage2.log"
def delconfirmation = input (id: 'delconfirmation', message: 'Proceed with mark as delete [YES/NO]?', parameters: [choice(choices: 'YES\nNO', description: "${delobjectsurl}", name: 'ONLINE_MARK_AS_DELETE')])
}
I tried with below options but still showing the description as plain text.
Configure Global Security
Is it possible to achieve which I am trying to do? I am using Jenkins v2.107.1.

Related

Grafana - Modify Alert Message

I am using Grafana version v8.3.3 and have set up Slack alerts but the alerts are formatted in a certain way and I don't see an option to change it.
There is a section Add details for your alert which is great but the alert contains all these fields and I can't find where to control which one to display in Slack message and which ones to hide. I just want to send a message with value and a brief description without annotations, labels, source, and silence.
**Firing**
Value: [ metric='disk_used_percent' labels={InstanceId=i-..., path=/} value=28.528058875324813 ]
Labels:
- alertname = CI Jenkins instance FREE space alert
- notification = slack
Annotations:
- summary = CI Jenkins instance is running out of space. Please investigate.
Source: http.....
Silence: http....
By providing custom message in contact point, I could able to avoid source, silence, query etc., being sent as part of alert notification message.

is there a way to see all the available methods of a plugin in Jenkins?

I am learning Jenkins on my own and I am trying to learn about plugins. I have a stage to send an email with the cppcheck results with a template I found here the template instantiate the CppcheckBuildAction and access its methods, what I would like to know if is possible to check what methods are avaialable for that instance and if possible how / where I can see them.
Also how could I for example echo / println one of them. For instance in the template provided in the link above it acces the total number of errors with ${cppcheckResult.report.getNumberTotal()} but if I echo it I get an error groovy.lang.MissingPropertyException: No such property: cppcheckResult for class: groovy.lang.Binding, this is what I tried
stage('Email') {
steps {
script{
publishCppcheck pattern:'cppcheck.xml'
emailext( subject: 'foo', to: 'mail#mail.net', body: '${JELLY_SCRIPT, template="custom"}')
}
echo "${cppcheckResult.report.getNumberTotal()}"
}
}
my final goal actually is to send the email just when the report find a new error so I was thinking to save the total number of errors in an external file and compare it with each build and if the number is bigger send the email, is there any native / easier way to do this?
Most plugins should have a javadoc link. At bottom of plugin,should see javadoc
And then there's the Extension Index for core and plugins.

How to pass pipeline variables to post build gerrit message?

I have a Pylint running in a Jenkins pipeline. To implement it, I used Gerrit trigger plugin and Next Generation Warnings plugin. Everything is working as expected - Jenkins is joining the review, checks change with pylint and generates report.
Now, I'd like to post pylint score in a custom "Build successful" message. I wanted to pass the pylint score to a environment variable and use it in dedicated window for Gerrit plugin message.
Unfortunately no matter what I try, I cannot pass any "new" variable to the message. Passing parameters embedded in pipeline works (e.g. patchset number).
I created new environment variable in Configure Jenkins menu, tried exporting to shell, writing to it (via $VAR and env. syntax) but nothing works - that is, build message displays raw string like $VAR instead of what variable contains.
What should I do to pass local pylint score (distinct for every pipeline occurence) to the custom build message for Gerrit?
I don't think the custom message can be used for this. This is just supposed to be a static message.
They way I do this is to use the SSH command to perform the review. You can also achieve the same using the REST API.
First I run my linting and white space checking script that will generate a json file with the information I would like to pass to Gerrit. Next I send it to Gerrit using SSH. See below my pipeline script and an example json file.
As a bonus I have added the robot comments. This will now show up in your review as a remark from Jenkins that line 8 of my Jenkins file has a trailing white space. You can easily replace this with your lint result of you like or just ignore it and only put the message. It is easier to use a json file as it will make it easier to create multi line messages
node('master') {
sh """
cat lint_change.json | ssh -p ${env.GERRIT_PORT} ${env.GERRIT_HOST} gerrit review ${env.GERRIT_PATCHSET_REVISION} --json
"""
}
Example json file:
{
"labels": {
"Code-Style": "-1"
},
"message": "Lint Bot Review\nLint Results:\n Errors: 0\n Warnings: 0\n\nWhitespace results:\n Errors: 1",
"robot_comments": {
"Jenkinsfile": [
{
"robot_id": "lint-bot",
"line": "8",
"message": "trailing whitespace."
}
]
}
}
Alternatively, you may want to look at a new gerrit-code-review-plugin that should make this things even easier. However, I have not tried this yet.

Jenkins pipeline mandatory text parameters in input step

We are building several pipeline tasks in Jenkins to make life easier on some deploy jobs. One of them requires manual input of several parameters. For that we are using an input step like this:
def userInput = input ( message : 'Select deployment versiĆ³n and input deployment code:',
parameters: [[$class: 'TextParameterDefinition', defaultValue: '', description: 'Clarive code', name: 'code']] )
Those parameters are mandatory. We didn't find in the documentation any property that will make the TextParameterDefinition mandatory. For now we are re running the step until all parameters are not null, but the solution is a bit confusing for the user.
Is there another way to handle mandatory parameters that avoids running the same step on a loop?
There was a plugin that did that but is no longer maintained.
There's an open bug to support it.
In the meantime what you can do is check if your parameter is present and if not throw an error like:
if (params.SomeParam == null) {
error("Build failed because of this and that..")
}

Display input step as popup so that its intuitive in Jenkins Pipeline

I am using Input step in my Jenkins Pipeline. In Teamcity, input step is very intuitive where a popup is displayed to accept the input.
In Jenkins Pipeline, the build pauses with a link to "Input Requested" to accept the input.
Is there a way to display the input step as a popup in Jenkins Pipeline similar to Teamcity one?
Yes, when you are using Pipelines and you are using the View Pipeline plugin, you should run your project and execute your input steps inside a STAGE, for example:
stage 'check-in'
node ('master') {
input 'Are you sure?'
}
And will get something like:
Instead, if you are monitoring the console, you will be prompted as you described.
While it's not exactly the same, the UI rewrite plugin called Blue Ocean ( https://wiki.jenkins-ci.org/display/JENKINS/Blue+Ocean+Plugin ) is now past 1.0 and has a much better interface for the input step.
I used this Jenkinsfile:
node(){
stage("primary"){
echo 'test'
input "This is a question?"
}
}
And here's how it looks in Blue Ocean:
Blue Ocean Example
Agreed. But I was looking for something similar to teamcity one because this is still not intuitive to the user. I guess may be this is the best we can get in jenkins.
#tulika how is this achieved in teamcity?
input 'Deploy to Production?'
gives me
input: not found
Process exited with code 127

Resources