You've already forked jenkins-lib
forked from jenkins/jenkins-lib
Исправлено получение переменных среды
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package ru.pulsar.jenkins.library
|
package ru.pulsar.jenkins.library
|
||||||
|
|
||||||
|
import org.jenkinsci.plugins.workflow.support.actions.EnvironmentAction
|
||||||
|
|
||||||
interface IStepExecutor {
|
interface IStepExecutor {
|
||||||
|
|
||||||
boolean isUnix()
|
boolean isUnix()
|
||||||
@@ -21,4 +23,6 @@ interface IStepExecutor {
|
|||||||
void tool(String toolName)
|
void tool(String toolName)
|
||||||
|
|
||||||
void withSonarQubeEnv(String installationName, Closure body)
|
void withSonarQubeEnv(String installationName, Closure body)
|
||||||
|
|
||||||
|
EnvironmentAction env()
|
||||||
}
|
}
|
@@ -1,5 +1,7 @@
|
|||||||
package ru.pulsar.jenkins.library
|
package ru.pulsar.jenkins.library
|
||||||
|
|
||||||
|
import org.jenkinsci.plugins.workflow.support.actions.EnvironmentAction
|
||||||
|
|
||||||
class StepExecutor implements IStepExecutor {
|
class StepExecutor implements IStepExecutor {
|
||||||
|
|
||||||
private steps
|
private steps
|
||||||
@@ -54,4 +56,9 @@ class StepExecutor implements IStepExecutor {
|
|||||||
body()
|
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.IStepExecutor
|
||||||
import ru.pulsar.jenkins.library.configuration.JobConfiguration
|
import ru.pulsar.jenkins.library.configuration.JobConfiguration
|
||||||
import ru.pulsar.jenkins.library.ioc.ContextRegistry
|
import ru.pulsar.jenkins.library.ioc.ContextRegistry
|
||||||
|
import ru.pulsar.jenkins.library.utils.Logger
|
||||||
import ru.pulsar.jenkins.library.utils.VersionParser
|
import ru.pulsar.jenkins.library.utils.VersionParser
|
||||||
|
|
||||||
class SonarScanner implements Serializable {
|
class SonarScanner implements Serializable {
|
||||||
@@ -25,7 +26,7 @@ class SonarScanner implements Serializable {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
def env = System.getenv();
|
def env = steps.env();
|
||||||
|
|
||||||
def sonarScannerBinary
|
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.IStepExecutor
|
||||||
import ru.pulsar.jenkins.library.ioc.ContextRegistry
|
import ru.pulsar.jenkins.library.ioc.ContextRegistry
|
||||||
@@ -7,7 +7,7 @@ class Logger implements Serializable {
|
|||||||
static void printLocation() {
|
static void printLocation() {
|
||||||
IStepExecutor steps = ContextRegistry.getContext().getStepExecutor()
|
IStepExecutor steps = ContextRegistry.getContext().getStepExecutor()
|
||||||
|
|
||||||
def env = System.getenv();
|
def env = steps.env();
|
||||||
steps.echo("Running on node $env.NODE_NAME")
|
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() {
|
def call() {
|
||||||
|
ContextRegistry.registerDefaultContext(this)
|
||||||
|
|
||||||
Logger.printLocation()
|
Logger.printLocation()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user