小编Mar*_*son的帖子

如何在Perl中修改Windows NTFS权限?

我在Windows Server 2003上使用ActiveState Perl.

我想在Windows NTFS分区上创建一个目录,然后授予Windows NT安全组对该文件夹的读取权限.在Perl中这可能吗?我是否必须使用Windows NT命令或是否有Perl模块来执行此操作?

一个小例子将非常感谢!

permissions perl winapi

5
推荐指数
2
解决办法
3455
查看次数

如何将项添加到ISet <T>?

我有三个叫Broker,InstrumentBrokerInstrument.

using Iesi.Collections.Generic;

public class Broker : ActiveDefaultEntity
{
    public virtual string Name { get; set; }
    public virtual ISet<BrokerInstrument> BrokerInstruments { get; set; }
}

public class Instrument : Entity
{
    public virtual string Name { get;  set; }
    public virtual string Symbol {get;  set;}
    public virtual ISet<BrokerInstrument> BrokerInstruments { get; set; }
    public virtual bool IsActive { get; set; }        
}

public class BrokerInstrument : Entity
{
    public virtual Broker Broker { …
Run Code Online (Sandbox Code Playgroud)

c# collections

5
推荐指数
1
解决办法
8102
查看次数

正则表达式从完全限定的域名中提取主机名

我对正则表达式非常生疏,需要一个从完全限定域名(FQDN)中提取主机名,这是我所拥有的示例:

myhostname.somewhere.env.com
myotherhostname.somewhereelse.insomeotherplace.byh.info
Run Code Online (Sandbox Code Playgroud)

我想回来

myhostname
myotherhostname
Run Code Online (Sandbox Code Playgroud)

非常感谢您的帮助

我尝试过,"(.+)\."但是它匹配了右边的字符串并产生了:

myhostname.somewhere.env.
myotherhostname.somewhereelse.insomeotherplace.byh.
Run Code Online (Sandbox Code Playgroud)

regex

5
推荐指数
1
解决办法
2万
查看次数

从写入STDOUT的函数返回值的最佳方法是什么?

我有一些帮助函数写入STDOUT用于记录目的.其中一些函数会向调用者返回一个值,但会返回该函数的整个输出.所以我的问题是如何让我的函数写入STDOUT并将一个值返回给调用者而不会使函数调用期间发出的所有STDOUT污染返回值?我正在寻找某种设计模式或最佳实践.

考虑这个脚本:

Function a
{
    Write-Output "In Function a"
    $a = 4
    return $a   
}

$b = a

Write-Output "Outside function: `$b is $b"
Run Code Online (Sandbox Code Playgroud)

输出是

Outside function: $b is In Function a 4

但我希望输出为:

In Function a
$b is 4
Run Code Online (Sandbox Code Playgroud)

powershell function powershell-2.0

5
推荐指数
1
解决办法
3486
查看次数

如何在 C# 中覆盖枚举上的 ToString()?

我在项目中的所有类和命名空间之外声明了以下枚举:

public enum ServerType { Database, Web } // there are more but omitted for brevity

我想用以下内容覆盖该ToString()方法:

public override string ToString(ServerType ServerType)
{
    switch (ServerType)
    {
        case ServerType.Database:
            return "Database server";
        case ServerType.Web:
            return "Web server";
    }
    // other ones, just use the base method
    return ServerType.ToString();
}
Run Code Online (Sandbox Code Playgroud)

但是我收到一个错误 no suitable method found to override

使用我自己的方法转换为字符串时是否可以覆盖枚举?

c# enums overriding c#-5.0

5
推荐指数
1
解决办法
6985
查看次数

如何从 Azure DevOps 管道将机密写入 azure key Vault?

我已经使用 ARM 在 Azure DevOps 中创建了一个 Key Vault,现在我想在同一管道中向它写入一个密钥。

我使用以下内联 PowerShell 创建了一个 Azure PowerShell 任务:

$secretvalue = ConvertTo-SecureString $(Secret) -AsPlainText -Force
Set-AzureKeyVaultSecret -VaultName $(VaultName) -Name $(SecretName) -SecretValue (ConvertTo-SecureString $(Secret) -AsPlainText -Force)
Run Code Online (Sandbox Code Playgroud)

密钥保管库创建得很好,但在尝试写入密钥时出现以下错误:

[error]Access denied

如果我Set-AzureKeyVaultSecret在本地机器上运行它工作正常。

编辑

这是我所做的一些屏幕截图。在 Azure DevOps 中,我创建了一个服务连接并验证了它:

在此输入图像描述

以下是将机密写入保管库的 Azure PowerShell 任务的样子:

在此输入图像描述

在此输入图像描述

在此输入图像描述

密钥保管库权限:

在此输入图像描述

在此输入图像描述

我是否需要单独的服务主体,或者是否需要创建应用程序注册?

powershell azure azure-keyvault azure-devops

5
推荐指数
1
解决办法
4694
查看次数

为什么我不能删除Perl中的这个空目录?

我正在从http://www.perlmonks.org/index.pl?node_id=217166转换linux脚本,具体如下:

#!/usr/bin/perl -w
use strict;
use Getopt::Std;
use File::Find;

@ARGV > 0 and getopts('a:', \my %opt) or die << "USAGE";
# Deletes any old files from the directory tree(s) given and
# removes empty directories en passant.
usage: $0 [-a maxage] directory [directory ...]
       -a  maximum age in days, default is 120
USAGE

my $max_age_days = $opt{a} || 120;

find({
    wanted => sub { unlink if -f $_ and -M _ > $max_age_days },
    postprocess => sub { …
Run Code Online (Sandbox Code Playgroud)

perl directory-traversal find

4
推荐指数
2
解决办法
2246
查看次数

如何通过 Gitlab 推送在 Jenkins 中使用参数进行构建?

我让 GitLab Community Edition 8.15.2 使用 webhook 成功触发 Jenkins 2.32.1 中的管道项目。我希望 gitlab 推送触发带有参数的构建,但当它通过时参数值为空,因此构建失败。

gitlab webhook 如下所示:

http://jenkins.server:8080/project/project-a/buildWithParameters?MYPARAM=foo

在我的管道项目中,我回显参数值

echo "MYPARAM: ${MYPARAM}"

并且它没有设置任何内容。关于我哪里出错了有什么想法吗?

更新

我在管道中使用的实际代码是:

node {
    try {
        echo "VM_HOST: ${VM_HOST}"
        echo "VM_NAME: ${VM_NAME}"
        stage('checkout') {

            deleteDir()
            git 'http://git-server/project/automated-build.git'
        }
        stage('build') {

            bat 'powershell -nologo -file Remove-MyVM.ps1 -VMHostName %VM_HOST% -VMName "%VM_NAME%" -Verbose'
        }
        ...
    }
}     
Run Code Online (Sandbox Code Playgroud)

该参数VM_HOST有默认值,但VM_NAME没有。在 Jenkins 的控制台输出中我可以看到:

[Pipeline] echo
VM_HOST: HyperVHost
[Pipeline] echo
VM_NAME: 
Run Code Online (Sandbox Code Playgroud)

webhooks jenkins gitlab jenkins-pipeline

4
推荐指数
1
解决办法
1万
查看次数

是否可以为 Jenkins 文件夹中的所有项目设置一些环境变量?

我在 Jenkins 2.32.1 的一个文件夹中有一组项目,我希望它们(在这个文件夹中)在构建运行时加载几个环境变量。这可能吗?我有文件夹插件并查看了但没有看到任何配置它的地方。

jenkins jenkins-plugins jenkins-pipeline

4
推荐指数
2
解决办法
1836
查看次数

如何从Jenkins管道脚本中的远程仓库克隆目录?

我在GitHub Enterprise中有一个大型仓库,需要在我的Jenkins构建服务器上克隆一个子目录,然后构建该子目录.我正在使用管道脚本并立即拥有此功能:

node {
    stage ('checkout') {
        git url: 'git@github.devops.mycompany.local:Org/MyLargeRepo.git'
    }
}
Run Code Online (Sandbox Code Playgroud)

我想要的是克隆 github.devops.mycompany.local:Org/MyLargeRepo/path/to/subproject

我知道我可能需要使用稀疏检出,但似乎无法解决如何在Jenkins管道脚本中配置它.有任何想法吗?

git github jenkins jenkins-pipeline

4
推荐指数
1
解决办法
7545
查看次数