mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
c190deee44
* use sonar go in groovy * use SONAR_TOKEN * only use owner/repo if both are set * trim version to major version digit * fix code climate issues * remove Sonar defaults * use sonar go step * use SONAR_TOKEN * use certs from parameters * use docker workspace & options * add instance parameter * implement branchName * implement branchName * remove duplicate default * update docs * fix TODOs * remove merge mess * fix code climate issue * address comments * respect custom defaults and custom config file name * fix typo * remove obsolete test cases * disable CommonStepChecks * check step config instead of context config * remove TODOs * respect jenkins PR envvars * use value from stepConfig * Update vars/sonarExecuteScan.groovy * rename options to config * correct type for options * add test cases * log sonar.options in debug message Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
80 lines
2.9 KiB
Groovy
80 lines
2.9 KiB
Groovy
import static org.hamcrest.Matchers.containsString
|
|
import static org.hamcrest.Matchers.hasItem
|
|
import static org.hamcrest.Matchers.is
|
|
import static org.hamcrest.Matchers.allOf
|
|
|
|
import org.junit.Before
|
|
import org.junit.Rule
|
|
import org.junit.Test
|
|
import org.junit.rules.RuleChain
|
|
import org.junit.rules.ExpectedException
|
|
import static org.junit.Assert.assertThat
|
|
|
|
import util.BasePiperTest
|
|
import util.JenkinsDockerExecuteRule
|
|
import util.JenkinsShellCallRule
|
|
import util.JenkinsReadYamlRule
|
|
import util.JenkinsStepRule
|
|
import util.JenkinsLoggingRule
|
|
import util.Rules
|
|
|
|
class SonarExecuteScanTest extends BasePiperTest {
|
|
private ExpectedException thrown = ExpectedException.none()
|
|
private JenkinsReadYamlRule readYamlRule = new JenkinsReadYamlRule(this)
|
|
private JenkinsStepRule jsr = new JenkinsStepRule(this)
|
|
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
|
|
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
|
|
private JenkinsDockerExecuteRule jedr = new JenkinsDockerExecuteRule(this)
|
|
|
|
@Rule
|
|
public RuleChain rules = Rules
|
|
.getCommonRules(this)
|
|
.around(readYamlRule)
|
|
.around(thrown)
|
|
.around(jedr)
|
|
.around(jscr)
|
|
.around(jlr)
|
|
.around(jsr)
|
|
|
|
def sonarInstance
|
|
|
|
@Before
|
|
void init() throws Exception {
|
|
sonarInstance = null
|
|
helper.registerAllowedMethod("withSonarQubeEnv", [String.class, Closure.class], { string, closure ->
|
|
sonarInstance = string
|
|
return closure()
|
|
})
|
|
helper.registerAllowedMethod("unstash", [String.class], { stashInput -> return []})
|
|
helper.registerAllowedMethod("fileExists", [String.class], { file -> return file })
|
|
helper.registerAllowedMethod('string', [Map], { m -> m })
|
|
helper.registerAllowedMethod('withCredentials', [List, Closure], { l, c ->
|
|
try {
|
|
binding.setProperty(l[0].variable, 'TOKEN_'+l[0].credentialsId)
|
|
c()
|
|
} finally {
|
|
binding.setProperty(l[0].variable, null)
|
|
}
|
|
})
|
|
helper.registerAllowedMethod('withEnv', [List.class, Closure.class], { List envVars, Closure body ->
|
|
body()
|
|
})
|
|
nullScript.commonPipelineEnvironment.setArtifactVersion('1.2.3-20180101')
|
|
}
|
|
|
|
@Test
|
|
void testWithCustomTlsCertificates() throws Exception {
|
|
jsr.step.sonarExecuteScan.loadCertificates(
|
|
customTlsCertificateLinks: [
|
|
'http://url.to/my.cert'
|
|
]
|
|
)
|
|
// asserts
|
|
assertThat(jscr.shell, allOf(
|
|
hasItem(containsString('wget --directory-prefix .certificates/ --no-verbose http://url.to/my.cert')),
|
|
hasItem(containsString('keytool -import -noprompt -storepass changeit -keystore .certificates/cacerts -alias \'my.cert\' -file \'.certificates/my.cert\''))
|
|
))
|
|
assertJobStatusSuccess()
|
|
}
|
|
}
|