我有一个简单的groovy脚本:
node ("master")
{
echo "I am about to try to use String.format"
def jjj = String.format("bob")
echo jjj
}
Run Code Online (Sandbox Code Playgroud)
如果我将此脚本直接放入我的作业配置并运行它,它运行正常.
但是,如果我将该脚本放入一个文件中然后通过"SCM的工作流脚本"加载,我就会收到错误
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: unclassified staticMethod java.lang.String format java.lang.String
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?是否可以关闭"SCM工作流脚本"的沙箱,就像"工作流脚本"一样?
或者是否有一些沙盒批准的格式化字符串的方式?
为什么它阻止我首先格式化字符串?
我可以Jenkins.instance.getItem('job_name')在脚本控制台或 Jenkinsfile 中按名称访问作业。
但是我无法为多分支管道或文件夹中的任何其他工作执行此操作。如果我尝试使用项目的全名(包括文件夹),例如 Jenkins.instance.getItem('folder_name/job_name'),我只会得到null结果。
如何访问文件夹中的作业?
鉴于上课
public class B
{
public bool flag = false;
public B()
{
}
}
Run Code Online (Sandbox Code Playgroud)
当我用线初始化它时
var jjj = new B(){flag = true};
Run Code Online (Sandbox Code Playgroud)
如果我在构造函数B()中放置一个断点,则flag为false.我预计它是真的,因为我在初始化时调用了"flag = true".
我究竟做错了什么?
假设我有一个简单的范围,通过Push-Location和Pop-Location以书结尾:
Function MyFunction($Location)
{
Push-Location $Location
# do other stuff here
Pop-Location
}
Run Code Online (Sandbox Code Playgroud)
有没有办法在范围的开头设置它,这样我就不必记得将Pop-Location放在最后?像这样的东西:
Function MyFunction($Location)
{
Setup-BothPushAndPopHere $Location
# do other stuff here
# at the end of the scope, Pop-Location is automatically called
}
Run Code Online (Sandbox Code Playgroud) 我有一个简单的脚本
Param([string] $myStringValue)
echo $myStringValue
Run Code Online (Sandbox Code Playgroud)
当我打电话给它时./test.ps1 -myStringValue steve,它运作得很好.
但是如果我在开头添加Set-StrictMode:
Set-StrictMode -Version Latest
Param([string] $myStringValue)
echo $myStringValue
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
> ./test.ps1 -myStringValue steve
The variable '$myStringValue' cannot be retrieved because it has not been set.
At D:\code\cadgraphics\test.ps1:2 char:20
+ Param([string] $myStringValue)
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (myStringValue:String) [], RuntimeException
+ FullyQualifiedErrorId : VariableIsUndefined
The variable '$myStringValue' cannot be retrieved because it has not been set.
At D:\code\cadgraphics\test.ps1:3 char:10
+ echo $myStringValue
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (myStringValue:String) [], …Run Code Online (Sandbox Code Playgroud) 我知道从stl类继承是一个坏主意.但有没有其他方法来扩展它们?
让我们说为了提高可读性,我希望能够在我的向量上调用"add"方法而不是可读性较低的"push_back".
或许我想在我的std :: map中添加一个简单的hasKey方法.
除了创建一个以std :: vector作为成员的整个包装类,将每个函数调用从我的包装器传递给向量之外,有什么方法可以做到这一点吗?
我需要能够读取/写入包含中文字符的文件 unicode 字符串。
文档说 CFile::typeUnicode “仅在派生类中使用”,但我找不到对使用它的任何派生类的任何引用。
是否有任何“官方”版本的 CFile 允许我读取和写入 unicode?
或者我最好尝试使用这样的东西:http://www.codeproject.com/Articles/4119/CStdioFile-driven-class-for-multibyte-and-Unicode
在Google Test中,当我运行以下测试时:
void ThrowInvalidArgument()
{
throw new std::invalid_argument("I am thrown an invalid_argument");
}
TEST(ExpectExceptions, Negative)
{
ASSERT_THROW(ThrowInvalidArgument(), std::invalid_argument);
}
Run Code Online (Sandbox Code Playgroud)
我得到以下失败:
error: Expected: ThrowInvalidArgument() throws an exception
of type std::invalid_argument.
Actual: it throws a different type.
[ FAILED ] ExpectExceptions.Negative (1 ms)
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
鉴于此类具有unique_ptr:
class MyClass
{
public:
MyClass(){}
MyClass(MyClass &&other) : ptr(std::move(other.ptr)){}
std::unique_ptr <int> ptr;
};
Run Code Online (Sandbox Code Playgroud)
有没有办法让它成为可能std::vector<MyClass>?
void ThisBreaksIt()
{
MyClass instance;
std::vector<MyClass> mv;
mv.push_back(instance);
}
Run Code Online (Sandbox Code Playgroud)
原样,这给了我错误
error C2248: 'std::unique_ptr<_Ty>::unique_ptr' : cannot access private member declared in class 'std::unique_ptr<_Ty>'
Run Code Online (Sandbox Code Playgroud)
这是有道理的,因为我没有复制构造函数,并且当编译器尝试创建默认复制构造函数时,它会尝试复制unique_ptr,这是不允许的.
我可以通过添加这个构造函数使其编译:
MyClass(const MyClass&){}
Run Code Online (Sandbox Code Playgroud)
但是,当然,这会留下unique_ptr未初始化的,而不是我想要的.
我无法补充
MyClass(const MyClass& other) : ptr(std::move(other.ptr)){}
Run Code Online (Sandbox Code Playgroud)
因为它是const,我不能在一个const对象上调用std :: move().我可以创建构造函数
MyClass(MyClass& other) : ptr(std::move(other.ptr)){}
Run Code Online (Sandbox Code Playgroud)
但是没有解决原始编译错误,因为vector::push_back使用了const复制构造函数.
所以,我被困住了.有没有办法做我想做的事情?
如果我只使用一个shared_ptr而不是,那么所有这些问题都会消失unique_ptr.那是我应该做的吗?
在一台机器上,调用git checkout不会创建本地分支.
例如,如果我有一个远程跟踪分支origin/master,我可以打电话git checkout origin/master,它会正常工作,让我处于无头状态.
但如果我试着打电话git checkout master,我就会收到错误error: pathspec 'master' did not match any file(s) known to git.
我在另一台机器上试过这个,它运行得很好.
他们安装了完全相同版本的git(2.15.0.windows.1). git config --list显示出一个区别.正常工作的机器在其配置中具有以下行:
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
Run Code Online (Sandbox Code Playgroud)
什么会把它放在本地配置中,为什么它可能会从其中一个系统中丢失,以及解决问题的正确方法是什么?
如果我想要特定提交时文件的内容,我可以使用命令git show [revision]:[filename],例如git master:Jenkinsfile.
如何获取特定提交时文件的对象 ID,而不是文件的内容?
我有一个包含一个文件(subdir/a.txt)的存储库,以及一个版本,添加它.
如果我hg convert使用包含的文件映射运行include subdir/a.txt,它可以正常工作.
但是,如果文件映射是include subdir/*.txt,include */a.txt或include **/*.txt,则生成的存储库中没有修订.
是否可以在文件映射中使用通配符hg convert?
-
我想这样做的原因是我可以创建一个包含历史记录的新存储库,但没有任何二进制文件.我希望能够做类似的事情exclude **/*.dll.有没有办法做到这一点?
Enum EventType = {Click, Jump, Etc};
Run Code Online (Sandbox Code Playgroud)
而不是像这样访问它:
EventType.Jump
Run Code Online (Sandbox Code Playgroud)
如果没有"EventType",有没有办法这样做.字首?
Jump
Run Code Online (Sandbox Code Playgroud)