我正在尝试为jenkins groovy脚本获取我的分支名称.我无法获取当前的分支名称.我尝试以下方法:
stage('Check out code')
checkout scm
echo "My branch is: ${env.BRANCH_NAME}"
Run Code Online (Sandbox Code Playgroud)
这是输出 - 它总是返回null.
Checking out Revision 33b531b2f1caaf8b64d968e437306f39d2dba1da (origin/pipeline)
> git.exe config core.sparsecheckout # timeout=10
> git.exe checkout -f 33b531b2f1caaf8b64d968e437306f39d2dba1da
[Pipeline] echo
My branch is: null
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
从这篇文章中使用 C 中的模拟对象进行单元测试:
这是通过使用
--wrap链接器选项来完成的,该选项将包装函数的名称作为参数。如果测试是使用 gcc 编译的,则调用可能如下所示:
$ gcc -g -Wl,--wrap=chef_cook waiter_test.c chef.c
在 Visual Studio 中编译 C 项目时如何做到这一点?
我之前已经与支持RFCOMM的蓝牙设备配对.当我的应用程序打开时,我不断尝试通过打开RFCOMM连接到设备.这样,当设备进入范围时,我的应用会自动连接.
deviceInfoCollection = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));
LogData(String.Format("Number of mldp devices is {0}", deviceInfoCollection.Count));
foreach (DeviceInformation deviceInfo in deviceInfoCollection)
{
LogData(String.Format("ID:{0}, NAME:{1}", deviceInfo.Id, deviceInfo.Name));
}
Run Code Online (Sandbox Code Playgroud)
然后在计时器上运行:
try
{
// The first time this method is invoked by a store app, it should be called
// from a UI thread in order to display the consent prompt
// https://msdn.microsoft.com/en-us/windows.devices.bluetooth.rfcomm.rfcommdeviceservice.fromidasync
RfcommDeviceService rfcommService = await RfcommDeviceService.FromIdAsync(deviceInfo.Id);
LogData(String.Format("ID:{0}, NAME:{1}", deviceInfo.Id, deviceInfo.Name));
}
catch (Exception)
{
LogData(String.Format("Can not request rfcomm service from device ID:{0}, NAME:{1}", deviceInfo.Id, deviceInfo.Name)); …Run Code Online (Sandbox Code Playgroud) 我有一个类将加载目录中的所有程序集,然后获取所有类型,看看它们是否实现了一个接口.我无法进行类型比较.在调试器中,如果总是未通过比较,我会看到我的类型已加载(我感兴趣的那个).如果我在本地使用相同的比较代码,则没有问题我得到了预期的结果.我可以在类型接口上进行sting比较,但我更愿意知道我做错了什么.
测试:
// Fails
[Fact]
public void FindISerialPortTest()
{
var path = Directory.GetCurrentDirectory();
var results = FindImplementers.GetInterfaceImplementor<ISerialPort>(path);
results.Length.Should().Be(1);
results[0].Should().BeAssignableTo<SerialPortWrapper>();
}
//Passes
[Fact]
public void DoesTypeImplementInterfaceTest()
{
var myType = typeof(SerialPortWrapper);
var myInterface = typeof(ISerialPort);
FindImplementers.DoesTypeImplementInterface(myType, myInterface).Should().Be(true);
}
Run Code Online (Sandbox Code Playgroud)
班级:
public class FindImplementers
{
public static T[] GetInterfaceImplementor<T>(string directory)
{
if (String.IsNullOrEmpty(directory)) { return null; } //sanity check
DirectoryInfo info = new DirectoryInfo(directory);
if (!info.Exists) { return null; } //make sure directory exists
var implementors = new List<T>();
foreach (FileInfo file in …Run Code Online (Sandbox Code Playgroud)
我正在努力创建一个带圆角的按钮,我不必为我想要使用的每种颜色创建一种新的按钮样式.我想做这样的事情:
<Grid Background="Wheat">
<Button Content="Test" HorizontalAlignment="Center" VerticalAlignment="Center" Width="300" Height="300"
Style="{StaticResource RoundedButtonStyle}" Background="Blue"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)
但父网格的背景总是影响按下按钮的颜色.我修改了默认按钮模板只是为了添加角半径.
如何创建一个使用按钮背景颜色的样式,并在按下时减轻它(而不是使用父背景)?
<Style TargetType="Button" x:Key="RoundedButtonStyle">
<Setter Property="Background" Value="{ThemeResource SystemControlBackgroundBaseLowBrush}" />
<Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}"/>
<Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundTransparentBrush}" />
<Setter Property="BorderThickness" Value="{ThemeResource ButtonBorderThemeThickness}" />
<Setter Property="Padding" Value="8,4,8,4" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
<Setter Property="FontWeight" Value="Normal" />
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
<Setter Property="UseSystemFocusVisuals" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid x:Name="RootGrid" Background="{TemplateBinding Background}" CornerRadius="10">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates"> …Run Code Online (Sandbox Code Playgroud) 我在地图上定义了多边形,纬度和经度作为坐标系.我想合并所有重叠的多边形.

来自这个问题
我找到了这个软件:软件
我下载了代码,它适用于笛卡尔坐标.但是,我不知道如何利用它来获得纬度和经度.
什么是解决这个问题的最佳方法?
例如,这里是我要合并的多边形:
var polyA = new List<GpsLocation>();
var pA1 = new GpsLocation(0, 0);
polyA.Add(pA1);
var pA2 = GpsHelper.CreateLocationBasedOnBearingDistance(pA1, 5, 100);
polyA.Add(pA2);
var pA3 = GpsHelper.CreateLocationBasedOnBearingDistance(pA2, 95, 100);
polyA.Add(pA3);
var pA4 = GpsHelper.CreateLocationBasedOnBearingDistance(pA3, 185, 100);
polyA.Add(pA4);
var polyB = new List<GpsLocation>();
var pB1 = GpsHelper.CreateLocationBasedOnBearingDistance(pA1, 95, 50);
polyB.Add(pB1);
var pB2 = GpsHelper.CreateLocationBasedOnBearingDistance(pB1, 5, 100);
polyB.Add(pB2);
var pB3 = GpsHelper.CreateLocationBasedOnBearingDistance(pB2, 95, 100);
polyB.Add(pB3);
var pB4 = GpsHelper.CreateLocationBasedOnBearingDistance(pB3, 185, 100);
polyB.Add(pB4);
Run Code Online (Sandbox Code Playgroud) 我试图从groovy中的正则表达式中获取匹配的字符串.匹配的字符串打印到控制台没有问题,但是当我尝试在git命令中使用匹配的字符串时,我收到以下错误:
Err: Incremental Build failed with Error: java.io.NotSerializableException: java.util.regex.Matcher
Run Code Online (Sandbox Code Playgroud)
这是代码:
def binaryName = "298_application_V2_00_Build_07.hex"
def matches = (binaryName =~ /(V)(\d+)(_)(\d+)(_)(Build)(_)(\d+)/)
versionTag = ""+matches[0].getAt(0)
echo "${matches}"
echo "$versionTag"
bat("git tag $versionTag")
bat("git push origin --tags")
Run Code Online (Sandbox Code Playgroud)
如何从正则表达式中获取匹配的字符串?
我希望能够在Jenkins Groovy脚本中添加回调作为参数。我认为关闭是我所需要的,但我不知道该怎么做。这是我想要的输出:
enter
hello
exit
Run Code Online (Sandbox Code Playgroud)
Jenkins文件:
def rootDir = pwd()
def tools = load "${rootDir}\\patchBuildTools.groovy"
mainMethod(tools.testCl("hello"))
Run Code Online (Sandbox Code Playgroud)
patchBuildTools.groovy
def mainMethod(Closure test) {
println "enter"
test()
println "exit"
}
def testCl(String message) {
println message
}
Run Code Online (Sandbox Code Playgroud)
这给了我输出:
hello
enter
java.lang.NullPointerException: Cannot invoke method call() on null object
Run Code Online (Sandbox Code Playgroud)
是否可以获取我想要的电话订单?
更新-根据答案
Jenkins文件:
def rootDir = pwd()
def tools = load "${rootDir}\\patchBuildTools.groovy"
mainMethod("enter", "exit")
{
this.testCl("hello")
}
Run Code Online (Sandbox Code Playgroud)
patchBuildTools.groovy
def mainMethod(String msg1, String ms2, Closure test) {
println msg1
test()
println ms2
}
def testCl(String message) …Run Code Online (Sandbox Code Playgroud)