use of org.jenkinsci.lib.configprovider.model.ConfigFile in project nodejs-plugin by jenkinsci.
the class NpmrcFileSupplyTest method test_supply_npmrc_with_registry.
@Test
public void test_supply_npmrc_with_registry() throws Exception {
StandardUsernameCredentials user = createUser("test-user-id", "myuser", "mypassword");
NPMRegistry privateRegistry = new NPMRegistry("https://private.organization.com/", user.getId(), null);
NPMRegistry officalRegistry = new NPMRegistry("https://registry.npmjs.org/", null, "@user1 user2");
Config config = createSetting("mytest", "email=guest@example.com", Arrays.asList(privateRegistry, officalRegistry));
FreeStyleBuild build = new MockBuild(j.createFreeStyleProject(), folder.newFolder());
FilePath npmrcFile = ConfigFileManager.provisionConfigFile(new ConfigFile(config.id, null, true), null, build, build.getWorkspace(), j.createTaskListener(), new ArrayList<String>(1));
assertTrue(npmrcFile.exists());
assertTrue(npmrcFile.length() > 0);
Npmrc npmrc = Npmrc.load(new File(npmrcFile.getRemote()));
assertTrue("Missing setting email", npmrc.contains("email"));
assertEquals("Unexpected value from settings email", "guest@example.com", npmrc.get("email"));
}
use of org.jenkinsci.lib.configprovider.model.ConfigFile in project nodejs-plugin by jenkinsci.
the class NodeJSCommandInterpreter method perform.
/*
* (non-Javadoc)
* @see hudson.tasks.CommandInterpreter#perform(hudson.model.AbstractBuild, hudson.Launcher, hudson.model.TaskListener)
*/
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, TaskListener listener) throws InterruptedException {
try {
EnvVars env = build.getEnvironment(listener);
EnvVars newEnv = new EnvVars();
// get specific installation for the node
NodeJSInstallation ni = getNodeJS();
if (ni == null) {
if (nodeJSInstallationName != null) {
throw new AbortException(Messages.NodeJSBuilders_noInstallationFound(nodeJSInstallationName));
}
// use system NodeJS if any, in case let fails later
nodeExec = (launcher.isUnix() ? Platform.LINUX : Platform.WINDOWS).nodeFileName;
} else {
Node node = build.getBuiltOn();
if (node == null) {
throw new AbortException(Messages.NodeJSBuilders_nodeOffline());
}
ni = ni.forNode(node, listener);
ni = ni.forEnvironment(env);
String exec = ni.getExecutable(launcher);
if (exec == null) {
listener.fatalError(Messages.NodeJSBuilders_noExecutableFound(ni.getHome()));
return false;
}
ni.buildEnvVars(newEnv);
// enhance env with installation environment because is passed to supplyConfig
env.overrideAll(newEnv);
nodeExec = ni.getExecutable(launcher);
if (nodeExec == null) {
throw new AbortException(Messages.NodeJSBuilders_noExecutableFound(ni.getHome()));
}
}
if (configId != null) {
// add npmrc config
ConfigFile cf = new ConfigFile(configId, null, true);
FilePath configFile = ConfigFileManager.provisionConfigFile(cf, env, build, build.getWorkspace(), listener, new ArrayList<String>());
newEnv.put(NodeJSConstants.NPM_USERCONFIG, configFile.getRemote());
build.addAction(new CleanTempFilesAction(configFile.getRemote()));
}
// add an Environment so when the in super class is called build.getEnviroment() gets the enhanced env
build.getEnvironments().add(Environment.create(newEnv));
} catch (AbortException e) {
// NOSONAR
listener.fatalError(e.getMessage());
return false;
} catch (IOException e) {
Util.displayIOException(e, listener);
e.printStackTrace(listener.fatalError(hudson.tasks.Messages.CommandInterpreter_CommandFailed()));
}
return internalPerform(build, launcher, listener);
}
use of org.jenkinsci.lib.configprovider.model.ConfigFile in project nodejs-plugin by jenkinsci.
the class NodeJSBuildWrapper method setUp.
/*
* (non-Javadoc)
* @see jenkins.tasks.SimpleBuildWrapper#setUp(jenkins.tasks.SimpleBuildWrapper.Context, hudson.model.Run, hudson.FilePath, hudson.Launcher, hudson.model.TaskListener, hudson.EnvVars)
*/
@Override
public void setUp(final Context context, Run<?, ?> build, FilePath workspace, Launcher launcher, TaskListener listener, EnvVars initialEnvironment) throws IOException, InterruptedException {
// get specific installation for the node
NodeJSInstallation ni = getNodeJS();
if (ni == null) {
throw new IOException(Messages.NodeJSBuilders_noInstallationFound(nodeJSInstallationName));
}
Computer computer = workspace.toComputer();
if (computer == null) {
throw new AbortException(Messages.NodeJSBuilders_nodeOffline());
}
Node node = computer.getNode();
if (node == null) {
throw new AbortException(Messages.NodeJSBuilders_nodeOffline());
}
ni = ni.forNode(node, listener);
ni = ni.forEnvironment(initialEnvironment);
String exec = ni.getExecutable(launcher);
if (exec == null) {
throw new AbortException(Messages.NodeJSBuilders_noExecutableFound(ni.getHome()));
}
ni.buildEnvVars(new EnvVarsAdapter(context));
EnvVars env = initialEnvironment.overrideAll(context.getEnv());
// add npmrc config
if (configId != null) {
ConfigFile cf = new ConfigFile(configId, null, true);
FilePath configFile = ConfigFileManager.provisionConfigFile(cf, env, build, workspace, listener, new ArrayList<String>());
context.env(NodeJSConstants.NPM_USERCONFIG, configFile.getRemote());
build.addAction(new CleanTempFilesAction(configFile.getRemote()));
}
}
Aggregations