I am using below command to retrieve baselines.
cleartool lsbl -fmt "%n\n" -comp comp_name@\vob_name -stream stream_name@\vob_name
I am searching for a way to display baselines which is numerically equal to/ less than certain given baseline. Is there any way to achieve it?
Case 1 : If output is
abc_6.2168
abc_7.4587
abc_8.2950
abc_9.3032
If I want to display baseline which is numerically equal to / less (and closest) to abc_8. Hence, the expected result in Case 1 should be : abc_8.2950.
Case 2 : If output is
abc_6.2168
abc_7.4587
abc_9.3032
Expected result should be : abc_7.4587
NOTE : Trying this on Groovy (Jenkins pipeline)
use strict;
use warnings;
use DBI;
my $bsl_find = $ARGV[0]; #baseline build package name
my $bsl;
my $c=0;
my $mat;
my $previous_str = q{};
my $final_baseline;
my $prev_num_count=1;
my $prev_num_len=1;
my $split_strng;
my $baseline_var = q{};
my $baseline_file;
my $all_baseline_file = $ARGV[1]; #file which contains the list of all retreived baselines as per ARGV[0]
my $app = $ARGV[2]; #the name of the application for which baseline is to be selected
my $filename = 'D:\\baseline_'.$app.'\\'.'new_'.$all_baseline_file.'.txt';
$baseline_file = 'D:\\baseline_'.$app.'\\'.'final_'.$all_baseline_file.'.txt';
$all_baseline_file = 'D:\\baseline_'.$app.'\\'.$all_baseline_file.'.txt';
open(my $fh, '<:encoding(UTF-8)',$filename)
or die "Could not open file '$filename' $!";
while (my $strng = <$fh>) {
chomp $strng;
#print "The line is : $strng \n";
$strng=~ s/^\s+|\s+$//;
#print " \n strng after trim is $strng.";
my $num_count = (split '_', $strng)[-1];
my $num_count_bsl_param = (split '_', $bsl_find)[-1];
my $num_len = length ($num_count);
my $num_len_bsl_param = length ($num_count_bsl_param);
my $a = substr($bsl_find, -$num_len_bsl_param);
my $b = substr($strng, -$num_len);
$split_strng = '_'.$a;
my ($substrng) = split /$split_strng/, $bsl_find;
if ($substrng =~ m/([^\_]+)$/)
{
$substrng=$1;
}
if ( ($a == $b) && (index($strng, $substrng) != -1) )
{
print "\n Match found";
$mat = $strng;
print "\n baseline found is : $mat";
$final_baseline = $mat;
print "\n final bsl is $bsl_find";
$baseline_var = $strng;
#exit 0;
goto label;
}
elsif ( ($a < $b) && (index($strng, $substrng) != -1) )
{
if ( (grep{/$bsl_find/} $filename) && ($previous_str eq "") ){
print "\n final baseline decided : $bsl_find";
$baseline_var = $bsl_find;
goto label;
}
elsif ( ($previous_str ne "") )
{
print "\n final baseline is ...: $previous_str";
$baseline_var = $previous_str;
goto label;
}
}
elsif ( ($a < $b) && ($previous_str ne "") && (index($strng, $substrng) != -1) )
{
if ( ($a > $c) && (index($previous_str, $substrng) != -1) )
{
print "\n baseline found is : $previous_str";
$final_baseline = $previous_str;
print " \n final is $final_baseline";
$baseline_var = $previous_str;
goto label;
}
}
elsif ( ($a < $b) && (index($bsl_find, $substrng) != -1) && ($previous_str ne "") && (index($previous_str, $substrng) == -1) )
{
print "\n Baseline not found of type $bsl_find.... final baseline is : $previous_str";
$baseline_var = $previous_str;
goto label;
}
close(fh);
}
if ($baseline_var eq "")
{
open my $fh ,"<",$filename;
my $last_line;
$last_line = $_,while (<$fh>);
print $last_line;
print " \n Baseline is $last_line";
$baseline_var = $last_line;
goto label;
close(fh);
}
label:
print " \n\n Writing $baseline_var to $baseline_file...";
#$baseline_var = $baseline_var.'.';
$baseline_var=~ s/^\s+|\s+$//;
print " \n \n baseline_var is $baseline_var. ";
unlink $baseline_file;
open(my $fh, '<:encoding(UTF-8)',$all_baseline_file)
or die "Could not open file '$all_baseline_file' $!";
while (my $word = <$fh>) {
chomp $word;
#print "\n word is $word.";
if ( $word =~ /\./ )
{
if( $word =~ m/$baseline_var\./ )
{
print "\n found $baseline_var. in $word";
open(FH1, '>', $baseline_file) or die $!;
print FH1 "$word";
}
}
else
{
if( $word eq $baseline_var )
{
print "\n found $baseline_var. in $word";
open(FH1, '>', $baseline_file) or die $!;
print FH1 "$word";
}
}
close(fh);
}
close(FH1);
}