小编jjs*_*jst的帖子

Jenkins管道插件:设置构建描述

我正在尝试用一个使用Jenkins管道插件的新作业替换目前使用旧式Jenkins作业攻击的当前构建管道,并Jenkinsfile从项目存储库中加载a .

遗留作业所做的一件事是使用Description setter插件将构建描述设置为包含Mercurial哈希,用户名和当前版本,以便易于查找构建.

有没有办法使用Jenkins管道插件复制/模拟此行为?

jenkins jenkins-workflow jenkins-pipeline

41
推荐指数
3
解决办法
3万
查看次数

根据特征中的抽象def获取val的null

在我的特性中混合val和def时,我看到了一些初始化的怪异.可以通过以下示例总结这种情况.

我有一个特性提供了一个抽象字段,我们称之为它fruit,应该在子类中实现.它还在val中使用该字段:

scala> class FruitTreeDescriptor(fruit: String) {
     |   def describe = s"This tree has loads of ${fruit}s"
     | }
defined class FruitTreeDescriptor

scala> trait FruitTree {
     |   def fruit: String
     |   val descriptor = new FruitTreeDescriptor(fruit)
     | }
defined trait FruitTree
Run Code Online (Sandbox Code Playgroud)

当覆盖fruita时def,事情按预期工作:

scala> object AppleTree extends FruitTree {
     |   def fruit = "apple"
     | }
defined object AppleTree

scala> AppleTree.descriptor.describe
res1: String = This tree has loads of apples
Run Code Online (Sandbox Code Playgroud)

但是,如果我覆盖fruit使用val... …

scala

10
推荐指数
1
解决办法
906
查看次数

ScalaCheck:选择具有自定义概率分布的整数

我想在ScalaCheck中创建一个生成器,生成介于1和100之间的数字,但是对于接近1的数字具有钟形偏向.

Gen.choose() 在最小值和最大值之间随机分配数字:

scala> (1 to 10).flatMap(_ => Gen.choose(1,100).sample).toList.sorted
res14: List[Int] = List(7, 21, 30, 46, 52, 64, 66, 68, 86, 86)
Run Code Online (Sandbox Code Playgroud)

并且Gen.chooseNum()对上限和下限有额外的偏见:

scala> (1 to 10).flatMap(_ => Gen.chooseNum(1,100).sample).toList.sorted
res15: List[Int] = List(1, 1, 1, 61, 85, 86, 91, 92, 100, 100)
Run Code Online (Sandbox Code Playgroud)

我想要一个choose()能给我一个看起来像这样的结果的函数:

scala> (1 to 10).flatMap(_ => choose(1,100).sample).toList.sorted
res15: List[Int] = List(1, 1, 1, 2, 5, 11, 18, 35, 49, 100)
Run Code Online (Sandbox Code Playgroud)

我看到了,choose()chooseNum()采用隐含的选择特征作为参数.我应该用吗?

scala scalacheck

6
推荐指数
1
解决办法
641
查看次数

在Python中处理除SIGINT之外的信号的"正确"方法?

我有一些Python代码需要能够处理SIGINT.为此,我使用了这样的东西:

def mymethod(*params):
  obj = MyObj(params)
  try:
    obj.do_some_long_stuff()
  except KeyboardInterrupt:
    obj.cleanup()
Run Code Online (Sandbox Code Playgroud)

真棒,真的很直白.是的,Python很棒!

但是,我现在还需要处理其他信号,即SIGTSTP和SIGQUIT.我正在尝试做的是类似的事情.这里有一些伪代码演示了我正在尝试用SIGTSTP做什么(我希望它足够清楚):

def mymethod(*params):
  obj = MyObj(params)
  try:
    obj.do_some_long_stuff()
  catch SIGINT:
    obj.cleanup()
  catch SIGTSTP:
    log_stop(obj) # Log that we stopped obj (add info about stop signal happening in obj-specific log file )
    raise SIGTSTP # Do normal SIGTSTP behavior as if we didn't catch the signal
Run Code Online (Sandbox Code Playgroud)

看来这里的方法是使用信号模块.但是,我的问题是我无法再访问对象状态,因为我可以使用KeyboardInterruptException:

import os
import signal

def handler(signum, frame):
  print "I can't access obj from here anymore!" # How to access obj …
Run Code Online (Sandbox Code Playgroud)

python signals

3
推荐指数
1
解决办法
3139
查看次数