我正在使用以下命令来检索基线。
cleartool lsbl -fmt "%nn" -comp comp_name@vob_name -stream stream_name@vob_name
我正在寻找一种显示数值等于/小于某些给定基线的基线的方法。有什么办法可以实现吗?
情况 1 : 如果输出为
abc_6.2168
abc_7.4587
abc_8.2950
abc_9.3032
如果我想显示数值上等于/小于(和最接近(abc_8的基线。因此,案例 1 中的预期结果应为:abc_8.2950。
情况 2 : 如果输出为
abc_6.2168
abc_7.4587
abc_9.3032
预期结果应为 : abc_7.4587
注意:在Groovy上尝试这个(Jenkins管道(
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 " nn 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);
}
有什么办法可以实现它吗?
不是单独使用 ClearCase/cleartool
,这意味着您需要解析其输出,这取决于您的操作系统/shell。
就像在Windows CMD shell中一样,在其路径中带有Git For Windows shell:
cleartool lsbl ... | sort -V |awk 'BEGIN{a=$0;FS="._"}$2 ^< 9{print $0;}'|tail -1
(需要^<
来转<
,并防止CMD将其解释为重定向(