com.marvelution.bamboo.plugins.variables.stamper.BuildVariablesStamper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bamboo-variables-stamper Show documentation
Show all versions of bamboo-variables-stamper Show documentation
Simple Task plugin that places all Variables of the BuildContext in a properties file
/*
* Licensed to Marvelution under one or more contributor license
* agreements. See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Marvelution licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.marvelution.bamboo.plugins.variables.stamper;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Map.Entry;
import java.util.Properties;
import org.apache.log4j.Logger;
import com.atlassian.bamboo.build.CustomPreBuildAction;
import com.atlassian.bamboo.plan.PlanKeys;
import com.atlassian.bamboo.repository.RepositoryException;
import com.atlassian.bamboo.utils.error.ErrorCollection;
import com.atlassian.bamboo.v2.build.BuildContext;
import com.atlassian.bamboo.v2.build.repository.RepositoryV2;
import com.atlassian.bamboo.variable.CustomVariableContext;
import com.atlassian.bamboo.ww2.actions.build.admin.create.BuildConfiguration;
/**
* Simple {@link CustomPreBuildAction} implementation to store all the variables in a properties file
*
* @author Mark Rekveld
*/
public class BuildVariablesStamper implements CustomPreBuildAction {
static final String FILENAME = "bamboo-variables.properties";
static final String DISABLE_STAMPER_KEY = "disable.variables.stamper";
private static final Logger LOGGER = Logger.getLogger(BuildVariablesStamper.class);
private static final String CREATED_BY_COMMENT = "Created by the Marvelution Bamboo Variables Stamper plugin";
private BuildContext buildContext;
private CustomVariableContext variableContext;
/**
* {@inheritDoc}
*/
public void init(BuildContext buildContext) {
this.buildContext = buildContext;
}
/**
* {@inheritDoc}
*/
public BuildContext call() throws InterruptedException, Exception {
Properties variables = new Properties();
variables.putAll(variableContext.getVariables(buildContext));
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Saving following variables to " + FILENAME);
for (Entry