How can I set the Jenkins assembly description when I run the assembly through curl?

I am trying to set the assembly description of the assembly that I am running as I am starting the assembly and I have not been lucky yet.

I came across a solution ( Adding text to the assembly page initiated by the remote Jenkins API ), and I kind of got it to work this way (the first command starts the assembly, the second sets the description of the last assembly):

curl -v -X POST "http://[myServer]/job/[jobName]/build" curl -v -X POST "http://[myServer]/job/[jobName/lastBuild/submitDescription" --data-urlencode "description=test description" 

However, the problem is that if the assembly that I just started falls into the queue / does not hit right away, "lastBuild" will not refer to the assembly that I just started, but before it (which is still being built).

So, I tried something like this:

 payload='json={""description"":""test description""}' curl -v -X POST -H "Content-Type: application/json" -d $payload "http://[myServer]/job/[jobName]/build" 

But in fact, he does not establish a description.

Any ideas on how this can be achieved?

Other solutions I found, but I'm not very happy with:

+6
source share
5 answers

You can always have a variable and pass the description of the construction to a variable on the initial call. Then, at the end of your assembly, output the variable to the console and run the Setter configuration plugin using the plugin .

Edit to clarify:

  • Install Description Plugin .
  • In the job configuration, configure the String parameter, name it " MyDescription ", leave the default values ​​empty.
  • Somewhere in the build steps, either echo Desc: $MyDescription or echo Desc: $MyDescription Windows Command echo Desc: $MyDescription or echo Desc: %MyDescription% , depending on your OS.
  • In the Post-Build steps, select Install Build Description .
    • Set the regex to ^Desc: (.*)
    • Set description as \1
  • At the launch command prompt:

curl -v -X POST --data-urlencode "MyDescription=This is my desc" "http://[myServer]/job/[jobName]/buildWithParameters"
(this is above one line)

+9
source

I had the same need - set the assembly description as soon as the assembly starts .
Please note that the Constructor Build plugin is activated as a post-build action, which is too late for me.
The way I solved this is to slightly change the configuration of the job and the Python script (but it can be in any language):

  • Add UUID parameter to job configuration
  • Created a script to send and set the description

The script does the following:

  • When submitting the assembly, create a uuid value (unique, right?) And fill in the UUID parameter
  • Interrogate the work of Jenkins (get JSON via the REST API), loop all the running assemblies, find mine (through the known UUID value). Limit polls to timeouts, so we don’t hang forever
  • Use the Jenkins Java CLI to set the description ( set-build-description command)

It works all the time, except when the assembly is queued (there are no free executors), and the timeout set above expires - I can do nothing.

+3
source

For those interested in using the Jenkins UI, I try:

The Postbuild plugin is much more powerful, but requires Groovy mastering and perms.

0
source

Another solution with the "Execute Groovy System script":

 def currentBuild = Thread.currentThread().executable def FOO = build.buildVariableResolver.resolve('FOO') currentBuild.setDescription(FOO) 
0
source

my download:

 String urlDownload = "https://dl.dropbox.com/s/ex4clsfmiu142dy/test.zip?token_hash=AAGD-XcBL8C3flflkmxjbzdr7_2W_i6CZ_3rM5zQpUCYaw&dl=1"; DownloadManager.Request request = new DownloadManager.Request(Uri.parse(urlDownload)); request.setDescription("Testando"); request.setTitle("Download"); request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "teste.zip"); final DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); final long downloadId = manager.enqueue(request); final ProgressBar mProgressBar = (ProgressBar) findViewById(R.id.progressBar1); new Thread(new Runnable() { @Override public void run() { boolean downloading = true; while (downloading) { DownloadManager.Query q = new DownloadManager.Query(); q.setFilterById(downloadId); Cursor cursor = manager.query(q); cursor.moveToFirst(); int bytes_downloaded = cursor.getInt(cursor .getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)); int bytes_total = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)); if (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)) == DownloadManager.STATUS_SUCCESSFUL) { downloading = false; } final double dl_progress = (bytes_downloaded / bytes_total) * 100; runOnUiThread(new Runnable() { @Override public void run() { mProgressBar.setProgress((int) dl_progress); } }); Log.d(Constants.MAIN_VIEW_ACTIVITY, statusMessage(cursor)); cursor.close(); } } }).start(); 

my statusMessage method:

 private String statusMessage(Cursor c) { String msg = "???"; switch (c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS))) { case DownloadManager.STATUS_FAILED: msg = "Download failed!"; break; case DownloadManager.STATUS_PAUSED: msg = "Download paused!"; break; case DownloadManager.STATUS_PENDING: msg = "Download pending!"; break; case DownloadManager.STATUS_RUNNING: msg = "Download in progress!"; break; case DownloadManager.STATUS_SUCCESSFUL: msg = "Download complete!"; break; default: msg = "Download is nowhere in sight"; break; } return (msg); } 
-4
source

Source: https://habr.com/ru/post/982446/


All Articles