I am using Jenkins version 1.567. I am trying to launch a Jenkins job from a URL by calling the buildWithParameters option.
My URL is set up like:
http://myjenkinsserver:8090/job/pc_test/buildWithParameters?token=PC123&Parm1=1
The job triggers perfectly well, however, I am presented with a blank, white screen. So I do not know if the job has succeeded or not unless I manually logon to Jenkins. This did not used to happen. Previously it would show the project page and I would be able to see the status of my job.
But I am not sure what has changed to make a blank page appear.
Can anyone suggest a solution whereby I can trigger the job via a URL and then see the results of the job?
Thanks.
A suitable workaround is using the build-with-parameters plugin.
Change the URL to:
http://myjenkinsserver:8090/job/pc_test/parambuild?token=PC123&Parm1=1
This will show you a page with the chosen build parameters. You need to confirm by clicking the Build button. Afterwards you are redirected to the project page.
You need to make a POST request to http://myjenkinsserver:8090/job/pc_test/build with json (value must be url encoded) parameter in the request body. The body for your example is (not url encoded yet so it's easy to read):
json={"parameter": {"name": "Parm1", "value": "1"}, "statusCode": "303", "redirectTo": "."}
and here is url encoded version(use this one):
json=%7B%22parameter%22%3A%20%7B%22name%22%3A%20%22Parm1%22%2C%20%22value%22%3A%20%221%22%7D%2C%20%22statusCode%22%3A%20%22303%22%2C%20%22redirectTo%22%3A%20%22.%22%7D
Also make sure that you set Content-Type: application/x-www-form-urlencoded
Full example using curl:
curl --data "json=on=%7B%22parameter%22%3A%20%7B%22name%22%3A%20%22Parm1%22%2C%20%22value%22%3A%20%221%22%7D%2C%20%22statusCode%22%3A%20%22303%22%2C%20%22redirectTo%22%3A%20%22.%22%7D" http://myjenkinsserver:8090/job/pc_test/build --verbose
Once you trigger the job, you can check its status using the Jenkins API.
See http://your-jenkins-host/api/ for more details. Look into the documentations.
I hope this helps.
This is an old question, but there is still fairly sparse information on this.
This is a sample of adding a "Deploy" button to the Build Description on Jenkins 2.89.4:
pipeline {
agent any
stages {
stage('Sample') {
steps {
sh 'echo "Sample"'
}
}
post {
success {
script {
currentBuild.description = "<form method='post' action='/job/sine-deploy/build'><input name='json' type='hidden' value=\"{'parameter': {'name': 'TRIGGERED_FROM_BUILD', 'runId': '${JOB_NAME}#${BUILD_NUMBER}'}, 'statusCode': '303', 'redirectTo': '/job/sine-deploy/'}\" /><input name='Submit' type='submit' value='Deploy' class='submit-button primary' /></form>"
}
}
}
}
}
Safe HTML needs to be turned on for the form to work.
Related
I have a Jenkinsfile script that tests for the possibility to perform an SVN merge and then asks the user for the permission to commit the merge.
I would like to know the username that answers the "input" step in order to write it into the commit message.
Is this possibile?
This is what hypothetically I would like to do:
outcome = input message: 'Merge trunk into branch?', ok: 'Merge'
echo "User that allowed merge: ${outcome.user}"
The input step got an optional submitterParameter, which allows to specify the key of the returned Map that should contain the user who's submitting the input dialog:
If specified, this is the name of the return value that will contain the ID of the user that approves this input.
The return value will be handled in a fashion similar to the parameters value.
Type: String
This looks then as follows:
def feedback = input(submitterParameter: 'submitter', ...)
echo "It was ${feedback.submitter} who submitted the dialog."
P.S: If anybody is interested in a full-fledged code snippet returning the user both for positive and negative feedback to the dialog (and timeout as well), I kindly point to our pipeline library.
It is not currently possible, for now only entry parameters are returned in the input step answer, as mentionned in source code :
// TODO: perhaps we should return a different object to allow the workflow to look up
// who approved it, etc?
switch (mapResult.size()) {
case 0:
return null; // no value if there's no parameter
case 1:
return mapResult.values().iterator().next();
default:
return mapResult;
}
If you'd like to restrict which user(s) can approve the input step, you can however use the submitter parameter, e.g. :
input message: 'Approve ?', submitter: 'authorized-submitter'
EDIT
Since January 2017 it is now possible to request additional parameters to be sent. Please see StephenKing answer above.
If you are not asking for any parameters on the input, then adding the submitterParameter kind of worked. It didn't add it as a parameter on the return object, instead, it turned the returned object into a string with the username in it.
def feedback = input(submitterParameter: 'submitter')
echo "It was ${feedback} who submitted the dialog."
You can do this for exceptions if you turn off the groovy-sandbox:
try {
'Deploy to production?'
node {
sh 'echo deploying'
}
} catch(e) {
def user = e.getCauses()[0].getUser()
echo "Production deployment aborted by:\n ${user}"
}
I created a custom slash command in Slack. The backend code, not that it's important, is a Lambda function in Python in AWS.
My problem is that when I enter the slash command, I am the only one who can see the message. Otherwise, it works perfectly. Is there a way to get others to see the output from my custom slash command?
See "'In Channel' vs. 'Ephemeral' responses" here: https://api.slack.com/slash-commands#responding_to_a_command.
By default, the response messages sent to commands will only be
visible to the user that issued the command (we call these "ephemeral"
messages). However, if you would like the response to be visible to
all members of the channel in which the user typed the command, you
can add a response_type of in_channel to the JSON response, like this:
{
"response_type": "in_channel",
"text": "It's 80 degrees right now.",
"attachments": [
{
"text":"Partly cloudy today and tomorrow"
}
]
}
When the response_type is in_channel, both the response message and the initial message typed by the user will be shared in
the channel.
If you have a block in your JSON payload to slack (you used slacks block-kit) e.g
`"blocks": []`
you'll have to put the "response_type": "in_channel" above blocks for it to work :) e.g
{
"response_type": "in_channel",
"blocks": [....]
}
I want to POST data from Postman Google Chrome extension.
I want to make 10 requests with different data and it should be at the same time.
Is it possible to do such in Postman?
If yes, can anyone explain to me how can this be achieved?
I guess there's no such feature in postman as to run concurrent tests.
If I were you, I would consider Apache jMeter, which is used exactly for such scenarios.
Regarding Postman, the only thing that could more or less meet your needs is - Postman Runner.
There you can specify the details:
number of iterations,
upload CSV file with data for different test runs, etc.
The runs won't be concurrent, only consecutive.
Do consider jMeter (you might like it).
Postman doesn't do that but you can run multiple curl requests asynchronously in Bash:
curl url1 & curl url2 & curl url3 & ...
Remember to add an & after each request which means that request should run as an async job.
Postman however can generate curl snippet for your request: https://learning.getpostman.com/docs/postman/sending_api_requests/generate_code_snippets/
I don't know if this question is still relevant, but there is such possibility in Postman now. They added it a few months ago.
All you need is create simple .js file and run it via node.js. It looks like this:
var path = require('path'),
async = require('async'), //https://www.npmjs.com/package/async
newman = require('newman'),
parametersForTestRun = {
collection: path.join(__dirname, 'postman_collection.json'), // your collection
environment: path.join(__dirname, 'postman_environment.json'), //your env
};
parallelCollectionRun = function(done) {
newman.run(parametersForTestRun, done);
};
// Runs the Postman sample collection thrice, in parallel.
async.parallel([
parallelCollectionRun,
parallelCollectionRun,
parallelCollectionRun
],
function(err, results) {
err && console.error(err);
results.forEach(function(result) {
var failures = result.run.failures;
console.info(failures.length ? JSON.stringify(failures.failures, null, 2) :
`${result.collection.name} ran successfully.`);
});
});
Then just run this .js file ('node fileName.js' in cmd).
More details here
Not sure if people are still looking for simple solutions to this, but you are able to run multiple instances of the "Collection Runner" in Postman. Just create a runner with some requests and click the "Run" button multiple times to bring up multiple instances.
Run all Collection in a folder in parallel:
'use strict';
global.Promise = require('bluebird');
const path = require('path');
const newman = Promise.promisifyAll(require('newman'));
const fs = Promise.promisifyAll(require('fs'));
const environment = 'postman_environment.json';
const FOLDER = path.join(__dirname, 'Collections_Folder');
let files = fs.readdirSync(FOLDER);
files = files.map(file=> path.join(FOLDER, file))
console.log(files);
Promise.map(files, file => {
return newman.runAsync({
collection: file, // your collection
environment: path.join(__dirname, environment), //your env
reporters: ['cli']
});
}, {
concurrency: 2
});
In postman's collection runner you can't make simultaneous asynchronous requests, so instead use Apache JMeter instead. It allows you to add multiple threads and add synchronizing timer to it
If you are only doing GET requests and you need another simple solution from within your Chrome browser, just install the "Open Multiple URLs" extension:
https://chrome.google.com/webstore/detail/open-multiple-urls/oifijhaokejakekmnjmphonojcfkpbbh?hl=en
I've just ran 1500 url's at once, did lag google a bit but it works.
The Runner option is now on the lower right side of the panel
If you need to generate more consecutive requests (instead of quick clicking SEND button). You can use Runner. Please note it is not true "parallel request" generator.
File->New Runner Tab
Now you can "drag and drop" your requests from Collection and than keep checked only request you would like to generate by a Runner setting 10 iterations (to generate 10 requests ) and delay for example to 0 (to make it as fast as possible).
Easiest way is to get => Google Chrome "TALEND API TESTER"
Go to help + type in Create Scenario
...or just go to this link => https://help.talend.com/r/en-US/Cloud/api-tester-user-guide/creating-scenario
I was able to send several POST API calls simultaneously.
You can use Fiddler with started traffic capture to record manual queries from Postman, then select them in Fiddler's sessions list as much as you want and replay (press R key) - they would run in parallel.
https://docs.telerik.com/fiddler/generate-traffic/tasks/resendrequest
You can run multiple instances of postman Runner and run the same collection with different data files in each instance.
Open multiple postman. It replicates it and run concurrently.
I have written a custom Slash command that takes in a query from the user and returns an image.
The Server side which receives the Slash command retrieves the query from the user, and forms the Image URL http://example.com/file1.png and it sends back the response as <http://example.com/file1.png>. This is shown as a link in the response and is not unfurled. What could be the problem?
I even tried the following:
1) I sent back a JSON payload as given below:
{
"text":"http://example.com/file1.gif","unfurl_media":true
}
But that displayed the link again and did not unfurl it.
2) I tried
{
"text":"<http://example.com/file1.gif>","unfurl_media":true
}
But same results.
What could be the problem? Do I absolutely need a incoming webhook integration and send the message there ?
Did it work the first time, or had the URL previously been unfurled?
Slack will only automatically unfurl a URL once per hour in a given channel. If a user manually posts the URL and it is not unfurled because of this limit they will get an ephemeral message from SlackBot about it, however the unfurl just silently fails for slash commands or webhooks. I've hit this before in testing and had to make sure to change either the URL or the channel to verify things are working.
You should not need a manual attachment or a webhook or even the unfurl_media flag in the response (it's on by default for messages posted via webhooks/slash command).
I was having a similar issue with slash commands returning the text of my image url.
What you need to change is to use an object with an image_url for your image, and put that inside an attachments array.
Below is an example that returns the link of the image as text and the image itself.
{
"parse": "full",
"response_type": "in_channel",
"text": "http://example.com/file1.png",
"attachments":[
{
"image_url": "http://example.com/file1.png"
}
],
"unfurl_media":true,
"unfurl_links":true
}
{
"parse": "full",
"text": "http://example.com/file1.png",
"attachments":[
{
"image_url": "http://example.com/file1.png"
}
],
"unfurl_media":true,
"unfurl_links":true
}
Is it possible to access information about committers and/or culprits of a Jenkins workflow job when checking out from one or more SCMs (either via checkout() or other SCM steps like git/svn)?
The intention is to use that information to notify committers and/or culprits about the job status, for example in a mail step.
A small example of a workflow definition:
node {
// checkout from one or more SCMs, e.g.
git url: '<URL>'
checkout([$class:...])
...
// how can we know about committers or culprits at this point?
$committers = ??
// send a mail to committers or culprits
mail to: '$committers', subject: 'JENKINS', body: '<information about the job status>'
}
How could this be adapted to get a collection of the committers after running the SCM steps?
Edit:
I am currently working with Jenkins version 1.596.2 and Workflow: Aggregator version 1.6 and it seems this is an open issue in JENKINS-24141
This is now possible using the email-ext plugin.
def to = emailextrecipients([[$class: 'CulpritsRecipientProvider'],
[$class: 'DevelopersRecipientProvider'],
[$class: 'RequesterRecipientProvider']])
if (to != null && !to.isEmpty()) {
mail to: to, subject: "JENKINS", body: "See ${env.BUILD_URL}"
}
However, if you just want to send an email on failures, you may want to use Mailer (based on the email-ext pipeline examples):
step([$class: 'Mailer',
notifyEveryUnstableBuild: true,
recipients: emailextrecipients([[$class: 'CulpritsRecipientProvider'],
[$class: 'RequesterRecipientProvider']])])
Using groovy within a pipeline script:
#NonCPS // Necessary to allow .each to work.
def changelist() {
def changes = ""
currentBuild.changeSets.each { set ->
set.each { entry ->
changes += "${entry.commitId} by ${entry.author.fullName}\n"
}
}
changes
}
similar to the answer from #szym, but without the #NonCPS required:
def authors = currentBuild.changeSets.collectMany { it.toList().collect { it.author } }.unique()
As you found, pending JENKINS-24141 this is not supported. Changes to Jenkins core are required.
You can get the xml info for a job in which you will find the name of the person who committed the change along with the commit messages.
http://<Jenkins URL>:<Port Number>/job/<Jobname>/<BuildNumber>/api/xml?
Give this a go in your browser. Search for "user".
You can dump this information in a text file to process.
It seems that this feature was implemented inside the email-ext plugin but the author forgot to document the way we are supposed to use this.
Please check https://issues.jenkins-ci.org/browse/JENKINS-34763 -- and add a comment there, asking for an example. I already did.
You can fetch committers email :
committerEmail = sh (
script: 'git --no-pager show -s --format=\'%ae\'',
returnStdout: true
).trim()
and send:
emailext body: 'text you choose', subject: 'subject you choose', recipientProviders: [[$class: 'DevelopersRecipientProvider']], to: committerEmail
taken from : https://medium.com/#dilunika/find-the-git-commit-user-jenkins-pipeline-b6790613f8b5
In the emailext plugin you can provide culprits, developers, requestor etc in the recipientProviders directly.
emailext body: '',
recipientProviders: [culprits(),
developers(),
brokenBuildSuspects(),
brokenTestsSuspects(),
requestor()],
subject: ''
Description
Culprits: Sends email to the list of users who committed a change since the last non-broken build till now. This list at least always include people who made changes in this build, but if the previous build was a failure it also includes the culprit list from there.
Developers: Sends email to all the people who caused a change in the change set.
Broken Build suspects: Sends email to the list of users suspected of causing the build to begin failing.
Broken Test suspects: Sends email to the list of users suspected of causing a unit test to begin failing. This list includes committers and requestors of the build where the test began to fail, and those for any consecutive failed builds prior to the build in which the test began to fail.
Source: Jenkins Pipeline Syntax - Snippet Generator
If you want to notify the culprits who broke the build, You do not need to any checks, Use email plugin in jenkins. This plugin gives you option to send mails to commiter between past good build and current broken build.
If you are using "Editable email notifier plugin" You get option of send mail to culprit.
If you are using email plugin then you get the option "Send separate e-mails to individuals who broke the build".