/** * Checks if the specified expected location already contains the installed version of the tool. * * This check needs to run fairly efficiently. The current implementation uses the source URL of {@link Installable}, * based on the assumption that released bits do not change its content. */ protected boolean isUpToDate(FilePath expectedLocation, Installable i) throws IOException, InterruptedException { FilePath marker = expectedLocation.child(".installedFrom"); return marker.exists() && marker.readToString().equals(i.url); }
/** * Determines if the security settings seem to match the defaults. Here, we only * really care about and test for HudsonPrivateSecurityRealm and the user setup. * Other settings are irrelevant. */ /*package*/ boolean isUsingSecurityDefaults() { Jenkins j = Jenkins.get(); if (j.getSecurityRealm() instanceof HudsonPrivateSecurityRealm) { HudsonPrivateSecurityRealm securityRealm = (HudsonPrivateSecurityRealm)j.getSecurityRealm(); try { if(securityRealm.getAllUsers().size() == 1) { HudsonPrivateSecurityRealm.Details details = securityRealm.loadUserByUsername(SetupWizard.initialSetupAdminUserName); FilePath iapf = getInitialAdminPasswordFile(); if (iapf.exists()) { if (details.isPasswordCorrect(iapf.readToString().trim())) { return true; } } } } catch(UsernameNotFoundException | IOException | InterruptedException e) { return false; // Not initial security setup if no transitional admin user / password found } } return false; }
public Authentication authenticate() throws AuthenticationException, IOException, InterruptedException { if (userName==null) return command.getTransportAuthentication(); // no authentication parameter. fallback to the transport if (passwordFile!=null) try { password = new FilePath(command.checkChannel(), passwordFile).readToString().trim(); } catch (IOException e) { throw new BadCredentialsException("Failed to read "+passwordFile,e); } if (password==null) password = command.checkChannel().call(new InteractivelyAskForPassword()); if (password==null) throw new BadCredentialsException("No password specified"); UserDetails d = doAuthenticate(userName, password); return new UsernamePasswordAuthenticationToken(d, password, d.getAuthorities()); } };
String setupKey = iapf.readToString().trim(); String ls = System.lineSeparator(); LOGGER.info(ls + ls + "*************************************************************" + ls
public static String[] readParsingRules(final FilePath parsingRulesFile) throws IOException { try { return parsingRulesFile.readToString().split("\n"); } catch (InterruptedException ie) { throw new IOException(ie); } }
private String readTemplateFile(StepExecution stepExecution) { if (this.file == null) { return null; } try { FilePath child = loadFileFromWorkspace(stepExecution, this.file); return child.readToString(); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Checks if the specified expected location already contains the installed version of the tool. * * This check needs to run fairly efficiently. The current implementation uses the source URL of {@link Installable}, * based on the assumption that released bits do not change its content. */ protected boolean isUpToDate(FilePath expectedLocation, Installable i) throws IOException, InterruptedException { FilePath marker = expectedLocation.child(".installedFrom"); return marker.exists() && marker.readToString().equals(i.url); }
/** * Checks if the specified expected location already contains the installed * version of the tool. * * This check needs to run fairly efficiently. The current implementation * uses the souce URL of {@link Installable}, based on the assumption that * released bits do not change its content. */ protected boolean isUpToDate(FilePath expectedLocation, Installable i) throws IOException, InterruptedException { FilePath marker = expectedLocation.child(".installedFrom"); return marker.exists() && marker.readToString().equals(i.url); }
/** * Checks if the specified expected location already contains the installed version of the tool. * * This check needs to run fairly efficiently. The current implementation uses the souce URL of {@link Installable}, * based on the assumption that released bits do not change its content. */ protected boolean isUpToDate(FilePath expectedLocation, Installable i) throws IOException, InterruptedException { FilePath marker = expectedLocation.child(".installedFrom"); return marker.exists() && marker.readToString().equals(i.url); }
/** * Checks if the specified expected location already contains the installed version of the tool. * * This check needs to run fairly efficiently. The current implementation uses the souce URL of {@link Installable}, * based on the assumption that released bits do not change its content. */ protected boolean isUpToDate(FilePath expectedLocation, Installable i) throws IOException, InterruptedException { FilePath marker = expectedLocation.child(".installedFrom"); return marker.exists() && marker.readToString().equals(i.url); }
/** * Checks if the specified expected location already contains the installed version of the tool. * * This check needs to run fairly efficiently. The current implementation uses the souce URL of {@link Installable}, * based on the assumption that released bits do not change its content. */ protected boolean isUpToDate(FilePath expectedLocation, Installable i) throws IOException, InterruptedException { FilePath marker = expectedLocation.child(".installedFrom"); return marker.exists() && marker.readToString().equals(i.url); }
public static boolean areNpmPackagesUpToDate(FilePath expected, String npmPackages, long npmPackagesRefreshHours) throws IOException, InterruptedException { FilePath marker = expected.child(NPM_PACKAGES_RECORD_FILENAME); return marker.exists() && marker.readToString().equals(npmPackages) && System.currentTimeMillis() < marker.lastModified()+ TimeUnit.HOURS.toMillis(npmPackagesRefreshHours); }
private String readTemplate(String file) { if (file == null || file.isEmpty()) { return null; } try { return this.getContext().get(FilePath.class).child(file).readToString(); } catch (Exception e) { throw new IllegalArgumentException(e); } }
public static String getSpecStringFromSpecConf(SpecConfiguration specConfiguration, EnvVars env, FilePath workspace, PrintStream logger) throws IOException, InterruptedException { if (StringUtils.isNotBlank(specConfiguration.getFilePath())) { String filePath = specConfiguration.getFilePath().trim(); filePath = Util.replaceMacro(filePath, env); String spec = buildDownloadSpecPath(filePath, workspace, logger).readToString(); return Util.replaceMacro(spec.trim(), env); } if (StringUtils.isNotBlank(specConfiguration.getSpec())) { return Util.replaceMacro(specConfiguration.getSpec().trim(), env); } return ""; }
private String getDotCiYml(final DynamicBuild build) throws IOException, InterruptedException { final FilePath fp = new FilePath(build.getWorkspace(), ".ci.yml"); if (!fp.exists()) { throw new InvalidBuildConfigurationException("No .ci.yml found."); } return fp.readToString(); }
private FilePath getRemoteKeyPath(AbstractBuild<?, ?> build, Runner runner) throws IOException, InterruptedException { String keysDir = "debian-package-builder-keys"; String relativeKeyPath = new File(keysDir, getRepo(build, runner).getKeypath()).getPath(); File absoluteKeyPath = new File (Jenkins.getInstance().getRootDir(), relativeKeyPath); FilePath localKey = new FilePath(absoluteKeyPath); FilePath remoteKey = build.getWorkspace().createTextTempFile("private", "key", localKey.readToString()); remoteKey.chmod(0600); return remoteKey; }
@Override protected Void run() throws Exception { final String roleName = this.step.getRoleName(); final String policyFile = this.step.getPolicyFile(); Preconditions.checkArgument(roleName != null && !roleName.isEmpty(), "roleName must not be null or empty"); Preconditions.checkArgument(policyFile != null && !policyFile.isEmpty(), "policyFile must not be null or empty"); AmazonIdentityManagement iamClient = AWSClientFactory.create(AmazonIdentityManagementClientBuilder.standard(), Execution.this.getContext()); UpdateAssumeRolePolicyRequest request = new UpdateAssumeRolePolicyRequest(); request.withRoleName(roleName); request.withPolicyDocument(Execution.this.getContext().get(FilePath.class).child(policyFile).readToString()); iamClient.updateAssumeRolePolicy(request); Execution.this.getContext().get(TaskListener.class).getLogger().format("Updated trust policy of role %s %n", roleName); return null; }
@Override public MarathonBuilder read(final String filename) throws IOException, InterruptedException, MarathonFileMissingException, MarathonFileInvalidException { final String realFilename = filename != null ? filename : MarathonBuilderUtils.MARATHON_JSON; final FilePath marathonFile = workspace.child(realFilename); if (!marathonFile.exists()) { throw new MarathonFileMissingException(realFilename); } else if (marathonFile.isDirectory()) { throw new MarathonFileInvalidException("File '" + realFilename + "' is a directory."); } final String content = marathonFile.readToString(); this.json = JSONObject.fromObject(content); return this; }
@Override public SecureGroovyScript getSecureGroovyScript(FilePath projectWorkspace, AbstractBuild<?, ?> build, TaskListener listener) throws IOException, InterruptedException { EnvVars env = build.getEnvironment(listener); String expandedScriptFile = env.expand(this.scriptFile); String text = new FilePath(projectWorkspace, expandedScriptFile).readToString(); return new SecureGroovyScript(text, true, null).configuring(ApprovalContext.create()/* unused but just in case: */.withItem(build.getParent())); }
public void touchAndCommit(FilePath repo, String... names) throws Exception { for (String name : names) { FilePath toTouch = repo.child(name); if (!toTouch.exists()) { toTouch.getParent().mkdirs(); toTouch.touch(0); hg(repo, "add", name); } else { toTouch.write(toTouch.readToString() + "extra line\n", "UTF-8"); } } hg(repo, "commit", "--message", "added " + Arrays.toString(names)); }