When I use Jenkins pipeline through with Docker, I want to compare string value with Groovy script, but the compare result was wrong, the follow script is my groovy script and the output result:
Is there anyone can tell me how resolve this problem?
String runningContainerId = sh(script: "docker ps --filter=\"name=${appEnv}-${env.JOB_NAME}-${env.BUILD_NUMBER}\" -q | xargs", returnStdout: true)
//def runningImageId = sh(script: "docker images | grep ${appEnv}-${env.JOB_NAME}:${env.BUILD_NUMBER} | tr -s ' ' | cut -d ' ' -f 3 ", returnStdout: true)
println 'current container:' + runningContainerId
//println runningImageId
try{
def ret = sh(script: "docker ps --filter=\"name=${appEnv}-${env.JOB_NAME}\" -q | xargs", returnStdout: true)
def splitStr = ret.tokenize(" ")
println 'splitStr=>' + splitStr
String containerId = runningContainerId
println 'containerId=>' + containerId
for( String str in splitStr) {
print str == containerId
print 'str=>' + str
if ( str == containerId) {
print 'same string:' + str
} else {
print 'different string:' + str
}
}
Jenkins output result is:
splitStr=>[8abe81071b7f, 40e2292d5099, 4136bbdf9cc5]
[Pipeline] echo
containerId=>8abe81071b7f
[Pipeline] echo
false
[Pipeline] echo
str=>8abe81071b7f
[Pipeline] echo
different string:8abe81071b7f
[Pipeline] echo
false
[Pipeline] echo
str=>40e2292d5099
[Pipeline] echo
different string:40e2292d5099
[Pipeline] echo
false
[Pipeline] echo
str=>4136bbdf9cc5
[Pipeline] echo
different string:4136bbdf9cc5
Related
I have a range slider in my Advanced custom fields. I want the number to be the amount of list items that it echo's out. In example, i put the range slider on 4 in ACF then it needs to echo out:
Flywheel 1
Flywheel 2
Flywheel 3
Flywheel 4
This is the code i have but it's not working, can someone please fix the code?
<?php
$flywheelnumber = get_field('flywheels');
if( $flywheelnumber ) {
echo '<form class="checklist-list">';
echo '<ul>';
foreach($flywheelnumber) {
echo '<li>';
echo ( $numbers );
echo '</li>';
}
echo '</ul>';
echo '</form>'
}
?>
Thanks!!
you have to use for loop. you can try these codes,
<?php
$flywheelnumber = get_field( 'flywheels' );
if ( $flywheelnumber ) {
echo '<form class="checklist-list">';
echo '<ul>';
for ( $x = 1; $x <= count( $flywheelnumber ); $x ++ ) {
echo '<li>' . $x . '</li>';
}
echo '</ul>';
echo '</form>';
}
?>
How can I merge branch coverage of two or more runs?
Is any tool or lcov command exist?
Let's say that I have two test runs and would like to see summary branch coverage
gcc -O0 --coverage main.c -o test-coverage
test-coverage param1
lcov --capture --rc lcov_branch_coverage=1 --directory . --config-file ./lcovrc --output coverage1.info
test-coverage param2
lcov --capture --rc lcov_branch_coverage=1 --directory . --config-file ./lcovrc --output coverage2.info
Looks like it is needed to parse and merge files coverage1.info and coverage2.info
Is any solution exist already or I have to develop my own?
Developed the python script, which merges a list of files (line coverage is not accurate here)
def merge(files):
if (len(files) == 0):
return 0
covs = [open(f, "r").readlines() for f in files]
result = []
branch_number = 0
for i, line in enumerate(covs[0]):
if ('end_of_record' in line):
result.append(line)
else:
tmp = line.split(':')
tag = tmp[0]
data = tmp[1]
if (tag == 'BRDA'):
c = data.split(',')[-1]
if (c == '1\n'):
branch_number += 1
result.append(line)
else:
flag = 0
for j in covs[1:]:
if j[i].split(',')[-1] == '1\n':
branch_number += 1
result.append(j[i])
flag = 1
break
if flag == 0:
result.append(line)
elif (tag == 'BRH'):
result.append(tag + ":" + str(branch_number)+'\n')
else:
result.append(line)
return result
How can get the youtube video title and duration without using api key ?
I have checked Youtube Video title with API v3 without API key? link but this only give the title and not the duration.
So how can I get duration also without api key ?
To people looking for an answer to this in 2020. You can do this using the Youtube Iframe API. You don't need a API key!
First you insert the api link into the JS like so:
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
After that you create the player with the desired videoID like this:
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'SIWbjgPYcJY',
playerVars: {
'autoplay': 0,
'controls': 1
},
events: {
'onReady': onPlayerReady
}
});
}
Then you need to get the title and duration by assigning these in a variable to your HTML. We place this in the onPlayerReady.
function onPlayerReady(event) {
time = player.getDuration();
$(".dur").val(time);
title = player.getVideoData().title
$(".title").val(title);
}
Last thing is to put the player, duration and title in the HTML:
<div id="player"></div>
<br>
<span>Titel:</span><input class="title">
<br>
<span>duration:</span><input class="dur">
<br>
JSFIDDLE
You can use youtube-dl:
$ youtube-dl -e "https://www.youtube.com/watch?v=2i2khp_npdE"
Alan Walker - Sing Me To Sleep
$ youtube-dl --get-duration "https://www.youtube.com/watch?v=2i2khp_npdE"
3:12
Alternatively:
$ curl -s "https://www.youtube.com/watch?v=2i2khp_npdE" | tr '<' '\n' | awk -F'"' '/name="title"/ { print $4 }'
Alan Walker - Sing Me To Sleep
$ curl -s "https://www.youtube.com/watch?v=2i2khp_npdE" | awk -F'"' '/itemprop="duration"/ { print $4 }'
PT3M12S
You can use this bash function to convert from the Youtube format to seconds:
duration_calculation ()
{
local total_in_second=0
local hours=0
local minutes=0
local seconds=0
local duration="$1"
if [[ $duration =~ ^PT([0-9]{1,})H([0-9]{1,})M([0-9]{1,})S$ ]]; then
hours=$((hours + BASH_REMATCH[1]))
minutes=$((minutes + BASH_REMATCH[2]))
seconds=$((seconds + BASH_REMATCH[3]))
# PT1H4M H:M:00
elif [[ $duration =~ ^PT([0-9]{1,})H([0-9]{1,})M$ ]];then
hours=$((hours + BASH_REMATCH[1]))
minutes=$((minutes + BASH_REMATCH[2]))
# PT1H29S H:00:S
elif [[ $duration =~ ^PT([0-9]{1,})H([0-9]{1,})S$ ]]; then
hours=$((hours + BASH_REMATCH[1]))
seconds=$((seconds + BASH_REMATCH[2]))
# PT4M29S M:S
elif [[ $duration =~ ^PT([0-9]{1,})M([0-9]{1,})S$ ]]; then
minutes=$((minutes + BASH_REMATCH[1]))
seconds=$((seconds + BASH_REMATCH[2]))
# PT1H H:00:00
elif [[ $duration =~ ^PT([0-9]{1,})H$ ]]; then
hours=$((hours + BASH_REMATCH[1]))
# PT4M 00:M:00
elif [[ $duration =~ ^PT([0-9]{1,})M$ ]]; then
minutes=$((minutes + BASH_REMATCH[1]))
# PT29S S
elif [[ $duration =~ ^PT([0-9]{1,})S$ ]]; then
seconds=$((seconds + BASH_REMATCH[1]))
fi
total_in_seconds=$(( (hours * 3600) + (minutes * 60) + seconds ))
echo "$total_in_seconds"
}
I'm trying to define a variable into a jenkins pipeline dsl script by reading 3 files and concatenating the output. The 3 files content is:
file1 content is: 127
file2 content is: 0
file3 content is: 1
def var1 = readfile('file1')
def var2 = readfile('file2')
def var3 = readfile('file3')
def concatVar = "${var1} + '_' + ${var2} + '_' + ${var3}"
printin ${concatVar}
The output I expect would be
printIn${concatVar}
127_0_1
instead my output is:
printIn ${concatVar}
127
_0
_1
I know that I am wrong somewhere, but I don't know how to do it. Is there any of you familiar with the Jenkins pipepile dsl/groovy syntax?
Thanks guys
Try this..
def var1 = readfile('file1').trim()
def var2 = readfile('file2').trim()
def var3 = readfile('file3').trim()
def concatVar = "${var1} + '_' + ${var2} + '_' + ${var3}"
println ${concatVar}
I found that readFile does not clip off the end of line character
I could not separate my file:
chr2 215672546 rs6435862 G T 54.00 LowDP;sb DP=10;TI=NM_000465;GI=BARD1;FC=Silent ... ...
I would like to print first seven fields and from 8th field print just DP=10 and GI=BARD1. DP in GI info is always in 8th field. Fields are continue (...) so 8th field is not last.
I know how to extract 8th field :
awk '{print $8}' PLZ-10_S2.vcf | awk -F ";" '/DP/ {OFS="\t"} {print $1}'
of course how to extract first seven fields, but how to pipe it together? Between all fields is tab.
If DP= and GI= are always in the same position within $8:
$ awk 'BEGIN{FS=OFS="\t"} {split($8,a,/;/); $8=a[1]";"a[3]} 1' file
chr2 215672546 rs6435862 G T 54.00 LowDP;sb DP=10;GI=BARD1 ... ...
If not:
$ awk 'BEGIN{FS=OFS="\t"} {split($8,a,/;/); $8=""; for (i=1;i in a;i++) $8 = $8 (a[i] ~ /^(DP|GI)=/ ? ($8?";":"") a[i] : "")} 1' file
chr2 215672546 rs6435862 G T 54.00 LowDP;sb DP=10;GI=BARD1 ... ...
One way is to split() with semicolon the eight field and traverse all results to check which of them begin with DP or GI:
awk '
BEGIN { FS = OFS = "\t" }
{
split( $8, arr8, /;/ )
$8 = ""
for ( i = 1; i <= length(arr8); i++ ) {
if ( arr8[i] ~ /^(DP|GI)/ ) {
$8 = $8 arr8[i] ";"
}
}
$8 = substr( $8, 1, length($8) - 1 )
print $0
}
' infile
It yields:
chr2 215672546 rs6435862 G T 54.00 LowDP;sb DP=10;GI=BARD1 ... ...