mirror of
https://github.com/firstBitMarksistskaya/jenkins-lib.git
synced 2025-03-17 21:17:50 +02:00
Исправлено получение переменных среды
This commit is contained in:
parent
b3ace45d3a
commit
b2af725362
@ -1,5 +1,7 @@
|
||||
package ru.pulsar.jenkins.library
|
||||
|
||||
import org.jenkinsci.plugins.workflow.support.actions.EnvironmentAction
|
||||
|
||||
interface IStepExecutor {
|
||||
|
||||
boolean isUnix()
|
||||
@ -21,4 +23,6 @@ interface IStepExecutor {
|
||||
void tool(String toolName)
|
||||
|
||||
void withSonarQubeEnv(String installationName, Closure body)
|
||||
|
||||
EnvironmentAction env()
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package ru.pulsar.jenkins.library
|
||||
|
||||
import org.jenkinsci.plugins.workflow.support.actions.EnvironmentAction
|
||||
|
||||
class StepExecutor implements IStepExecutor {
|
||||
|
||||
private steps
|
||||
@ -54,4 +56,9 @@ class StepExecutor implements IStepExecutor {
|
||||
body()
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
EnvironmentAction env() {
|
||||
return steps.env
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package ru.pulsar.jenkins.library.steps
|
||||
import ru.pulsar.jenkins.library.IStepExecutor
|
||||
import ru.pulsar.jenkins.library.configuration.JobConfiguration
|
||||
import ru.pulsar.jenkins.library.ioc.ContextRegistry
|
||||
import ru.pulsar.jenkins.library.utils.Logger
|
||||
import ru.pulsar.jenkins.library.utils.VersionParser
|
||||
|
||||
class SonarScanner implements Serializable {
|
||||
@ -25,7 +26,7 @@ class SonarScanner implements Serializable {
|
||||
return
|
||||
}
|
||||
|
||||
def env = System.getenv();
|
||||
def env = steps.env();
|
||||
|
||||
def sonarScannerBinary
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package ru.pulsar.jenkins.library.steps
|
||||
package ru.pulsar.jenkins.library.utils
|
||||
|
||||
import ru.pulsar.jenkins.library.IStepExecutor
|
||||
import ru.pulsar.jenkins.library.ioc.ContextRegistry
|
||||
@ -7,7 +7,7 @@ class Logger implements Serializable {
|
||||
static void printLocation() {
|
||||
IStepExecutor steps = ContextRegistry.getContext().getStepExecutor()
|
||||
|
||||
def env = System.getenv();
|
||||
def env = steps.env();
|
||||
steps.echo("Running on node $env.NODE_NAME")
|
||||
}
|
||||
}
|
41
test/integration/groovy/printLocationTest.groovy
Normal file
41
test/integration/groovy/printLocationTest.groovy
Normal file
@ -0,0 +1,41 @@
|
||||
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition
|
||||
import org.jenkinsci.plugins.workflow.job.WorkflowJob
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.jvnet.hudson.test.JenkinsRule
|
||||
|
||||
class printLocationTest {
|
||||
|
||||
@Rule
|
||||
public JenkinsRule rule = new JenkinsRule()
|
||||
|
||||
@Before
|
||||
void configureGlobalGitLibraries() {
|
||||
RuleBootstrapper.setup(rule)
|
||||
}
|
||||
|
||||
@Test
|
||||
void "Logger should echo current node name"() {
|
||||
def pipeline = '''
|
||||
import ru.pulsar.jenkins.library.utils.Logger
|
||||
|
||||
pipeline {
|
||||
agent any
|
||||
stages {
|
||||
stage('test') {
|
||||
steps {
|
||||
printLocation()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'''.stripIndent()
|
||||
final CpsFlowDefinition flow = new CpsFlowDefinition(pipeline, true)
|
||||
final WorkflowJob workflowJob = rule.createProject(WorkflowJob, 'project')
|
||||
workflowJob.definition = flow
|
||||
|
||||
rule.assertLogContains('Running on node master', rule.buildAndAssertSuccess(workflowJob))
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
import ru.pulsar.jenkins.library.steps.Logger
|
||||
import ru.pulsar.jenkins.library.ioc.ContextRegistry
|
||||
import ru.pulsar.jenkins.library.utils.Logger
|
||||
|
||||
def call() {
|
||||
ContextRegistry.registerDefaultContext(this)
|
||||
|
||||
Logger.printLocation()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user