I'm trying to configure a Jenkins's Workflow (Trough workflow-plugin) that can work with dynamic node names in an environment in which slaves are managed automatically.
Unfortunately it turns out that node() does not support regex, nor the common wildcard *:
node('node-*') {
}
There is any way to make node() work with dynamic slave names?
OK This is sort of a RTFM situation:
https://github.com/jenkinsci/workflow-plugin/blob/master/TUTORIAL.md
The parameter may be a slave name, or a single label, or even a label
expression such as:
node('unix && 64bit') {
// as before }
So I can simply use a label to identify nodes.
Related
Is there a way to programmatically query (using .net SDK) list of running pipelines by data annotations?
I can set data annotation when I run pipeline as explained here, but not sure how to query pipelines or filter pipelines using the same?
According to the API documentation, query pipelines by annotation is not supported. Filter parameter support following:
Gets or sets parameter name to be used for filter. The allowed
operands to query pipeline runs are PipelineName, RunStart, RunEnd and
Status; to query activity runs are ActivityName, ActivityRunStart,
ActivityRunEnd, ActivityType and Status, and to query trigger runs are
TriggerName, TriggerRunTimestamp and Status. Possible values include:
'PipelineName', 'Status', 'RunStart', 'RunEnd', 'ActivityName',
'ActivityRunStart', 'ActivityRunEnd', 'ActivityType', 'TriggerName',
'TriggerRunTimestamp', 'RunGroupId', 'LatestOnly'
I have a DSL FreeStyleJob in jenkins. Let's say job/project named A is calling another job/project B as a post-build actions. I am making use of downstreamParameterized and passing currentBuild() paramaters as below
downstreamParameterized {
trigger(B) {
condition('SUCCESS')
parameters {
currentBuild()
}
}
}
And I know job/project B to be parameterized (Also DSL job). But how do I accept currentBuild() as a parameter in B. But I don't see any option related to it. Can anyone suggest?
See this pic for parameter options
I have already tried with predefined properties in job/project A and string parameters in job/project B and it works fine. But I don't want to follow this as there are many different type parameters in current build parameters.
I can't take file parameter options as both job workspace are different.
Solution is straight forward if the parameters are same for both the jobs. All you need to do is to declare the same set of parameters in JOB B as in JOB A. Jenkins will take care of passing the parameters to the downstream job.
As long as you have the same set of parameters in both the jobs it should work.
Reference :
Job 1 :
Job 2 :
Parameterized trigger in JOB 1
Thanks
Here is what I am trying to achieve. - I have two 'Choice Parameters' in my Jenkins job. The values of the first Choice Parameter are hard coded. The second choice list should be populated based on the first choice list selection. I have one properties file saved in Jenkins, which has key-value pairs. The values in first choice list and the Keys in the file are same. On selecting a value in first choice list i want a code to read the properties file and populate the second choice parameter with the values from file corresponding to that key.
For second choice list i am trying with 'Active Choice Reactive Parameter' , Referenced parameters= first_choice and below groovy script. But this is not returning any values. Please help!
def firstChoice = [first_choice]
Properties props = new Properties()
def stream = new FileInputStream('C:/Jenkins/books.properties')
try{
props.load(stream)
}
catch (Exception ex){
println "Exception"
}
finally {
stream.close()
}
def values = props.getProperty(firstChoice).split(",")
return values
Are the parameters defined in your job? if you're trying to inject parameters that are not defined in the job you need to either define them or add exception in Jenkins when you're loading the master service.
More reading:
https://wiki.jenkins-ci.org/display/JENKINS/Plugins+affected+by+fix+for+SECURITY-170
Follow this answer and use active choices parameter. This will help you achieve what you want to
https://stackoverflow.com/a/73742809/4781673
I'm making my first steps in using Redis under ZF2.
I was wondering if there is a method to retrieve keys by pattern.
e.g.:
after setting multiple values with keys like: 'stackOverflow_'.time(), i would like to retrieve later all keys matching the 'stackOverflow_' pattern.
tried using getItems(array $keys) with wildcard in: \vendor\zendframework\zendframework\library\Zend\Cache\Storage\Adapter\AbstractAdapter.php
$redisKeyPattern = 'stackOverflow_';
$redis = $this->getServiceLocator()->get('Redis');
$values = $redis->getItems(array($redisKeyPattern.'*'));
with no succces.
any ideas?
UDPATE:
thanks guys. i ended up with duplicating the Redis adapter and adding my own functionality that utilizes the 'keys' function in the Redis extension:
public function getItemsByKeyPattern($pattern) {
$keys = $this->getRedisResource()->keys('*'.$pattern.'*');
if(empty($keys)) return null;
foreach($keys as &$key){
$key = explode(':', $key)[1];
}
$items = parent::getItems($keys);
return $items;
}
and it works for me :)
sadly to say there is no method present to return items with a wildcard, also redis don't support namespaces for stored items.
you need to define each item you want to receive, maybe you should look at a implementation like this
$receiveRedisKeys = [];
foreach($resultSet as $result)
{
$receiveRedisKeys[] = 'predefined_prefix_' . $result->getId();
}
$redisCacheResultSet = $redis->getItems($receiveRedisKeys);
i know that someone on github made a new repository where he modified redis to allow namespaces but this requires that you build the redis binarys by yourself from source. this leeds to a redis version you can't update anymore over apt-get
It's not possible, but there are some alternatives.
One idea is to keep a set with the keys you are interested in. That is the most common approach to this problem: each time you create one of the keys you will want to retrieve later, you add its name to a set. Then when you need to operate on one of those keys, you can grab it from the set. Read this article to get a general idea about this approach.
Another idea is to use the SCAN command to walk the keyspace with the pattern you are using, and as a second step retrieve the values with MGET followed by the keys you collected. This approach is good for administrative processes, but not as something that should be included in an application because the performance will be worse than that of the first idea. More about SCAN.
Finally, an option that is not recommended but I'm listing it just for completeness is to use the KEYS command to collect the keys you want, then proceed to get the values with MGET, as in the SCAN approach. This is not recommended as KEYS shouldn't be used in production environments. More about KEYS.
I'm having an issue where calling .contains() on one of my domain classes' hasMany relationships is not doing the same when running normally, or when debugging. The situation is as follows:
I have 2 domain objects, A and B. A has a hasMany relationship with B.
class A {
...
static hasMany = [bees: B]
...
}
Now, during the execution of one of my filters, I grab my current user from the spring security service. This user also contains a single instance of B. What my filter should do is to check if the instance of B in the user is contained in some instance of A.
Assume that the instances of B are actually referring to the same object (since they are).
Now, the issue arises. Calling:
if (instanceOfA.bees.contains(user.instanceOfB)) {
println 'success'
} else {
println 'failure'
}
prints failure during normal (or debugging without stepping through the code) execution. However, if I put a break-point there, and step through the code, it correctly executes the contains() and prints success.
I have also implemented equals, hashCode and compareTo in an attempt to resolve this, but with the same behaviour.
This is usually due to lazyloading or cache. Use instanceOfA.bees.id.contains(user.instanceOfB.id) and it always works.
Maybe your user.instanceOfB object is a hibernate proxy object and therefore not a real B. You can check this using a debugger or printing user.instanceOfB.getClass().
You can use GrailsHibernateUtil.unwrapIfProxy(proxyObject) to get the real object from the proxy.
I would do this with HQL:
A.executeQuery("select a from A a join a.bees as b where b = :b and a = :a", [a: instanceOfA, b: user.instanceOfB])
So it seems that using one of the Groovy transform annotations seems to do the trick. Simply adding:
// uid is a uniqe UUID we use to identify with other systems.
#EqualsAndHashCode(includes = ["id", "uid"])
does the trick. Seems a bit strange that the IDE generated methods (using the same fields) did not...