Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: Job filter as a context variable #2974

Merged
merged 1 commit into from Dec 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/en/manual/04-jobs.md
Expand Up @@ -1654,6 +1654,7 @@ Job context variables:
* `job.retryAttempt`: A number indicating the attempt, if this execution is a [retry](#retry).
* `job.wasRetry`: `true` if this execution is a retry, otherwise `false`. See: [retry](#retry).
* `job.threadcount`: Threadcount (number of nodes run at once) of the Job
* `job.filter`: The filter used to select the nodes for this job (if applicable)

Node context variables:

Expand Down
5 changes: 3 additions & 2 deletions rundeckapp/grails-app/assets/javascripts/jobedit.js
Expand Up @@ -93,9 +93,10 @@ function _jobVarData() {
'user.email': {title: 'Email of user executing the job'},
'retryAttempt': {title: 'Retry attempt number'},
'wasRetry': {title: 'True if execution is a retry'},
'threadcount': {title: 'Job Threadcount'}
'threadcount': {title: 'Job Threadcount'},
'filter': {title: 'Job Node Filter Query'}
};
['id', 'execid', 'name', 'group', 'username', 'project', 'loglevel', 'user.email', 'retryAttempt', 'wasRetry', 'threadcount'].each(function (e) {
['id', 'execid', 'name', 'group', 'username', 'project', 'loglevel', 'user.email', 'retryAttempt', 'wasRetry', 'threadcount', 'filter'].each(function (e) {
_VAR_DATA['job'].push({key: 'job.' + e, category: 'Job', title: jobdata[e].title, desc: jobdata[e].desc});
});
}
Expand Down
Expand Up @@ -898,6 +898,9 @@ class ExecutionService implements ApplicationContextAware, StepExecutor, NodeSte
jobcontext.id = execution.scheduledExecution.extid
jobcontext.successOnEmptyNodeFilter=execution.scheduledExecution.successOnEmptyNodeFilter?"true":"false"
}
if (execution.filter) {
jobcontext.filter = execution.filter
}
jobcontext.execid = execution.id.toString()
jobcontext.executionType = execution.executionType
jobcontext.serverUrl = generateServerURL(grailsLinkGenerator)
Expand Down
24 changes: 24 additions & 0 deletions rundeckapp/test/unit/ExecutionServiceTests.groovy
Expand Up @@ -2092,4 +2092,28 @@ class ExecutionServiceTests {
assertNotNull(execs)
assertTrue(execs.contains(e2))
}

void testExportContextForExectuion(){
def filterFixture = "foo bar"

def ex = new Execution(
project: "test",
user: "test",
workflow: new Workflow(
commands: [
new CommandExec(adhocRemoteString: "exec")
]
),
filter: filterFixture
)

def lg = mockFor(org.codehaus.groovy.grails.web.mapping.LinkGenerator)
lg.demand.link(2..2) { return '' }

def jobcontext = ExecutionService.exportContextForExecution(ex, lg.createMock())

assertEquals(filterFixture, jobcontext.filter)

lg.verify()
}
}