how do i store the output of a command into a variable for use in a github-actions .yaml?
docker images --format='{{.ID}}' | select -first 1
gives me:
fc6e040841a1
i've seen stuff online about select-object..but i honestly have no idea, just trying to push an image to a registry...
the following cmd doesn't work in powershell:
for /f "delims=" %a in ("docker images --format='{{.ID}}' | select -first 1") do #set "%_img%=%a"
the following cmd doesn't work in powershell:
for /f "delims=" %a in ("docker images --format='{{.ID}}' | select -first 1") do #set "%_img%=%a"
That's because this is Command Prompt syntax. Specifically, everything outside of the () would only work under cmd.exe. The PowerShell equivalent for assigning a command result to a variable is:
$variableName = COMMAND
To apply it to your use case:
$imageId = docker images --format='{{.ID}}' | Select-Object -First 1
Note that select is an alias of Select-Object and either can be used interchangeably.
Edit: While not required for setting variables unlike in the Command Prompt, for syntax is still different in PowerShell when batch scripting. You can read up on PowerShell's for, foreach, and ForEach-Object constructs when you want to learn how they are used in PowerShell scripts, and watch for this gotcha when using the foreach "statement" as part of a pipeline.
While not part of the original scope of the question, since OP did ask and I answered in the comments, I will put the bash equivalent here for the sake of completeness and how I transposed this from the PowerShell method I used above:
imageId=$(docker images --format="{{.ID}}" | head -n 1)
This is similar to the PowerShell syntax with a few changes: remove the $ from the variable name on assignment, and Select-Object is replaced by head. You can't pad the = with whitespace, and you have to subshell the command with $().
Due to our projects is really huge and combined all targets into single compilation + analysis + publish will take much time to finished. So I'd like to running the klocwork analysis in parallel.
Here what I've got right now (split the targets in various sub tasks):
kw-analysis -> kw-analysis-sub-1
| -> kw-analysis-sub-2
| -> ...
| -> kw-analysis-sub-n
| |
| + the sub-task will handle:
| 1. compile single target and generate spec: kwinject_<target_name>.out :
| $ export KWWRAP_HOOKS_DIR='/temp/kw/hooks'
| $ export PATH=${KWWRAP_HOOKS_DIR}:$PATH
| $ make <target_name>
| $ kwinject --trace-in "/temp/kw/kwwrap.trace" --output "kwinject_<target_name>.out"
| 2. trace and anslysis for each target:
| $ kwbuildproject --url "<https://url:port>/<project_name>" [-I] --table-directory kwtable_<target_name> kwinject_<target_name>.out
| 3. archive kwtable_<target_name> folder
|
+ leading job will do:
1. copy all kwtable_<target_name> from sub-analysis jobs (downstream jobs)
2. deploy and publish the result into klocwork sever once for all
<<<<<< this is the key point of parallel analysis
As I know to publish single kwtable can be:
$ kwadmin --url <https://url:port> load --name <build_name> <project_name> kwtable_<target_name>
However, seems kwadmin neither support multiple kwtabels via:
kwadmin load --name <build_name> ... kwtable_<target_name_1> kwtable_<target_name_2> ...
nor support add additional result in exists build via
$ kwadmin load --name <build_name> ... kwtable_<target_name_1>
|
+ create build first
$ kwadmin "append" --name <build_name> ... kwtable_<target_name_2>
*
+ append new result in <build_name> for anothers kwtables folder
So, is there any way I can run klocwork analysis in parallel. Btw I'm using the Jenkins as integration tool
Running the parallel analysis by breaking the project into multiple pieces may take more time than building it as a single project with Klocwork sometimes. the reason behind this is, Klocwork is going to analyze all the dependent files multiple times as you perform multiple builds/analyses which are actually a part of a single project. (Parallel analysis can be a benefit when you do not have dependencies on different modules/files/pieces that you are building in parallel).
Klocwork can perform incremental/delta analysis when you pass --incremental argument as part kwbuildproject command. This should save the build time.
I have a Jenkins job to tweak, but no administration right on Jenkins itself.
I'd like to clean composer output from non readable characters, e.g:
the command is composer update --no-progress --ansi which outputs
in Jenkins'console.
I didn't exactly get the the reason why Jenkins cannot output some characters correctly.
As per https://medium.com/pacroy/how-to-fix-jenkins-console-log-encoding-issue-on-windows-a1f4b26e0db4, I perhaps could have tried to specify -Dfile.encoding=UTF8 for java, but as I said I don't have rights for Jenkins administration.
How could I get rid of these 'squares' characters ?
By pasting output lines into Notepad++, i noticed that these characters were backspaces. Hereafter how I've managed to embellish the output for Jenkins console :
# run the command, redirect the output into composer.out file
bin/composer.sh update --no-progress --ansi >composer.out 2>&1
# getting rid of backspaces
composer_out=$(cat composer.out | tr -d '\b')
# adding line feeds instead of numerous spaces
composer_out=$(echo "$composer_out" | sed -r 's/\)\s*(\w+)/\)\n\1/g')
echo "$composer_out"
I Have more than 1000 jobs in Jenkins,
And I would like to go through all of them in order to clean unused jobs.
What is the recommended way to do so?
I guess in every job "xml" file there is an indication to when it last ran,
Can anyone point me where this file is located?
I ended up filter the jobs by the "View job Filters" plugin,
You can use "Filter by Build Trend" option as follows:
Create a view for "All jobs" -> go to edit view -> in "add job filter " choose "Build Trend Filter" -> choose the filter you desire.
This is what I did:
I don't think you can do this in one step. But you can do this in 2 steps.
Find the URLs of all jobs with this:
https://jenkins-server/api/json?tree=jobs[url]
Get more info about each job by using the urls returned from step 1:
url-from-step1/api/json
This will give you the healthreport, last failed/successful build etc. If you need more info about these builds you can make a new request with :
url-from-step1/last-build-number/api/json
I recommend using JSON, and using JQ (http://stedolan.github.io/jq/, https://jqplay.org/) to parse your JSON
Happy coding!
You can leverage the REST API. The following urls might be relevant for you:
https://ci.jenkins-ci.org/api/xml?tree=jobs[name] -- to get a list of jobs
https://ci.jenkins-ci.org/job/{jobName}/lastBuild/buildTimestamp?format=yyyy-MM-dd-HH-mm-ss -- to get the time of last build of job {jobName}
Feel free to change xml to json/python...
I can provide a following shell script as a rough example:
#!/bin/bash
jenkinsUrlBase='https://ci.jenkins-ci.org'
callJenkins() {
curl --silent --show-error -g "$jenkinsUrlBase${1}"
}
callJenkins '/api/xml?tree=jobs[name]' | xmlstarlet sel -t -v '//hudson/job/name' | while read projectName ; do
timestamp=$(callJenkins "/job/${projectName}/lastBuild/buildTimestamp?format=yyyy-MM-dd-HH-mm-ss")
echo "Last build of ${projectName}: ${timestamp}"
done
You can exploit directory and file structure in ${JENKINS_HOME}:
cd ${JENKINS_HOME}/jobs/${JOB_NAME}/builds
ls -lt | head -2 | tail -1 | awk '{print $9}'
Example output:
2015-08-13_11-48-25
I would like to pack my firefox extension as xpi file. I tried by adding it to archive and name it as filename.xpi
But when i try to install it on firefox am getting "package corrupted" message. Is there any way i can create a valid xpi file ?
I have installed cygwin and tried to execute zip command to create xpi file. But got zip is not a command error.
Can somebody guide me to get it done ?
If you are on windows (to install cygwin it looks like you do), you can use the windows built in tool:
Select the contents of the extension (remember, don't select the outside folder).
Right Click
Send to
Compressed (zipped) folder
Then just replace the .zip for .xpi in the filename
Looks like your problem is on completing the point 1. correctly. Select only the contents of the extension. Not the folder that contains it.
So basically your zip file should have following structure:
my_extension.zip
|- install.rdf
|- chrome.manifest
|- <chrome>
and NOT this structure:
my_extension.zip
|- <my_extension>
|- install.rdf
|- chrome.manifest
|- <chrome>
I experienced the same problems today and found the error to be that the add-on was obviously not signed by Mozilla, causing Firefox to refuse the installation. Up until recently, it was possible to by-pass this security check by setting xpinstall.signatures.required to false in about:config. However, as of Firefox 46, signing is mandatory and no by-pass is provided any longer, see https://blog.mozilla.org/addons/2016/01/22/add-on-signing-update/ This means that one has to either downgrade to a previous version or use a non release channel version to test one's addons :(
Also, here's how I pack an extension for Firefox with command line 7z:
cd /the/extension/folder/
7z a ../<extension_name>.xpi * -r
(where 'a' stands for "add/create" and "-r" for recursive)
Or to update the extension with the file(s) we just edited:
cd /the/extension/folder/
7z u ../<extension_name>.xpi * -r
("u" for update the archive's content)
Two methods, using the GUI 7zFM.exe, or a command line or batch file.
1.0) GUI method. Assuming 7-Zip is installed with shell integration so you see 7-Zip show up in the context-menu (right-click of selected files) of Windows Explorer.
1.a) Go into the folder of your add-on.
1.b) Select all the files and folders you want to include in the .xpi. Assuming you don't have any files you want to ignore down in any sub-folders. If you do, you might want to use the command line option.
1.c) Right-click on the list of selected files, find the 7z icon, choose the Add to archive... option.
1.d) A dialog pops up. Edit the location and name of the zip file, change to .zip to .xpi, etc.
1.e) Note if you create the .xpi in the same folder, don't re-archive it in the future, as your add-on will fail horribly. You never want an .xpi ending up inside your .xpi by accident. I usually just create it in the parent folder, by adding ..\ to the beginning of the file name, e.g. ..\addon-1.2.3-fx.xpi
1.f) 7-Zip has a lot of powerful compression options, not all of which Firefox can handle. Choose settings which Firefox is able to process. Refer to image.
2.0) Command Line method. Assuming you're in Windows, and know how to open a command prompt, change drives and directories (a.k.a. folders).
2.a) CD to your add-on directory.
2.b) Use the most basic 7-Zip command line.
"C:\Program Files\7-Zip\7z.exe" a -tzip addon-1.2.3-fx.xpi *
2.c) You can get a smaller file by finding the exact command line options which correspond to the above GUI, namely:
"C:\Program Files\7-Zip\7z.exe" a -tzip -mx=9 -mm=Deflate -mfb=258 -mmt=8 "addon-1.2.3-fx.xpi" *
Note that there is no Dictionary size = 32kb option when using Deflate Compression method. Otherwise, the options are in order and correspond to the GUI.
|-----------------------|---------|--------------|
| Option / Parameter | GUI | Command line |
|-----------------------|---------|--------------|
| Archive format | zip | -tzip |
| Compression level | Ultra | -mx=9 |
| Compression method | Deflate | -mm=Deflate |
| Dictionary size | 32 KB | (none) |
| Word size | 258 | -mfb=258 |
| Number of CPU threads | 8 | -mmt=8 |
|-----------------------|---------|--------------|
| Additional Parameters | | |
|-----------------------|---------|--------------|
| Recurse into Folders | (none) | -r |
| Multiple passes | (none) | -mpass=15 |
| Preserve Timestamps | (none) | -mtc=on |
| Ignore files in list | | -x#{ignore} |
|-----------------------|---------|--------------|
Notes:
i) The multi-thread option (-mmt=8) is specific to my system which has 8 cores. You will need to lower this to 6 or 4 or 2 or 1 (i.e. remove option) if you have fewer cores, etc, or increase if you have more. Won't make much difference either way for a small extension.
ii) The option to recurse into folder may or may not be the default, so specifying this option should ensure proper recursion.
iii) The option to preserve windows timestamps (creation, access, modification) should default to on anyways, so may not be needed.
iv) The ignore files in list option is any file which has a list of files and wildcards of files you wish to exclude.
2.d) Advanced topic #1: ignore file list (examples)
|----------------|------------------------------------|
| What to Ignore | Why to Ignore |
|----------------|------------------------------------|
| TODO.txt | Informal reminders of code to fix. |
| *.xpi | In case you forget warning above! |
| .ignore | Ignore the ignore file list. |
| ignore.txt | Same thing, if you used this name. |
|----------------|------------------------------------|
"C:\Program Files\7-Zip\7z.exe" a -tzip -mx9 -mm=Deflate -mfb=258 -mmt=8 -mpass=15 -mtc=on "addon-1.2.3-fx.xpi" * -x#ignore.txt
2.e) Advanced topic #2: Batch file (Windows CMD.EXE), assuming fairly recent windows, i.e. from the 21st century. This can be as simple and rigid, or complex and flexible as you care to make it. A general balance is to assume you will be in the Command Prompt, in the top level directory of the add-on you are working on, and that you have intelligently named that directory to have the same basename of the .xpi file e.g. D:\dev\addon-1.2.3-fx directory for the addon-1.2.3-fx.xpi add-on xpi. This batch file makes this assumption, and dynamically figures out the correct basename to use for the .xpi.
#ECHO OFF
REM - xpi.bat - batch file to create Mozilla add-on xpi using 7-Zip
REM - This finds the folder name, and discards the rest of the full path, saves in an environment variable.
FOR %%* IN (.) DO SET XPI=%%~nx*
REM - Uncomment the DEL line, or delete .xpi file manually, if it gets corrupted or includes some other junk by accident.
REM DEL "%XPI%.xpi"
REM - Command line which does everything the GUI does, but also lets you run several passes for the smallest .xpi possible.
"C:\Program Files\7-Zip\7z.exe" a -tzip -r -mx=9 -mm=Deflate -mfb=258 -mmt=8 -mpass=15 -mtc=on "%XPI%.xpi" * -x#ignore.txt
REM - Cleanup the environment variable.
SET XPI=
When pack extension using 7z, compress into .zip and then rename to .xpi, dont compress i
Do as per the following while using 7z
Select only the inner contents and not the outer folder.
Enter the filename as filename.xpi and choose archive format as zip in the prompt that appears while zipping.
You will find a valid xpi file created.
Use the created xpi for installing your extension on firefox.
It works!
Just zip all the files and folders inside my_extension folder and change the resulting zipped file's extension to my_extension.xpi
/my_extension
|- defaults/
|- locale/
|- resources/
|- install.rdf
|- ... (other files and folders)
Installation of xpi file created from zipped file of my_extension folder will result error as
"This add-on could not be installed because it appears to be corrupt." error
I try myself to build a zip in several ways because I was convinced I do something wrong 'cause all i got was "package corrupted" stuff .
well.. not anymore and I do not even need to load it from Load temporary add-on (now i drag and drop the xpi file from the desktop over Waterfox and I install it as legit xpi file!
How I do that?
'Cause I try myself the github stuff I load it first in Load temporary add-on (url:about:debugging#addons) the xpi file using the method used by user314159 with the .bat file method that use 7zip.
after you load that you should read somewhere something similar to:
Extension ID
86257e65ca311ee368ffcee50598ce25733a049b#temporary-addon
then all you should do is add inside manifest.json modifying the "applications" :
"applications": {
"gecko": {
"strict_min_version": "54.0a1",
"id": "86257e65ca311ee368ffcee50598ce25733a049b#temporary-addon"
}
},
after this push Remove to uninstall the temporary addon then you should build the xpi again like you did before
now is a normal xpi file SIGNED what you can install normal ! (here is works without modifying anything else)
I use Waterfox x64 i's seems to be problems to Firefox
the answer is you should upload your extension on the hub then to use mozilla signing api
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/Distribution
Create file config.js
Insert code into config.js
//
try {
Components.utils.import("resource://gre/modules/addons/XPIProvider.jsm", {})
.eval("SIGNED_TYPES.clear()");
}
catch(ex) {}
Move config.js to application work folder, eg: C:\Program Files\Mozilla Firefox\
Create config-prefs.js and write code into:
pref("general.config.obscure_value", 0);
pref("general.config.filename", "config.js");
Place config-pres.js to C:\Program Files\Mozilla Firefox\defaults\pref\
Restart Firefox
Look result