Skip to content

Commit

Permalink
[JENKINS-48711] - PCT is now able to automatically determine the arti…
Browse files Browse the repository at this point in the history
…fact ID
  • Loading branch information
oleg-nenashev committed Dec 27, 2017
1 parent 2e0571a commit 1d20f1c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
12 changes: 9 additions & 3 deletions README.md
Expand Up @@ -17,21 +17,27 @@ You can find it [here](hub.docker.com/r/jenkins/pct/).
This command will clone of a repository and run PCT against the latest Jenkins Core:

```shell
docker run --rm -v maven-repo:/root/.m2 -v $(pwd)/out:/pct/out -e ARTIFACT_ID=job-restrictions -e VERSION=job-restrictions-0.6 -i jenkins/pct
docker run --rm -v maven-repo:/root/.m2 -v $(pwd)/out:/pct/out -e ARTIFACT_ID=job-restrictions -e VERSION=job-restrictions-0.6 jenkins/pct
```

This command will run PCT against custom versions of Jenkins and the plugin specified by volumes:

```shell
docker run --rm -v maven-repo:/root/.m2 -v $(pwd)/out:/pct/out -v my/jenkins.war:/pct/jenkins.war:ro -v my/plugin:/pct/plugin-src:ro -e ARTIFACT_ID=job-restrictions -i jenkins/pct
docker run --rm -v maven-repo:/root/.m2 -v $(pwd)/out:/pct/out -v my/jenkins.war:/pct/jenkins.war:ro -v my/plugin:/pct/plugin-src:ro jenkins/pct
```

This command will run PCT for a branch in a custom repository:

```
docker run --rm -v maven-repo:/root/.m2 -v $(pwd)/out:/pct/out -e CHECKOUT_SRC=https://github.com/oleg-nenashev/job-restrictions-plugin.git -e VERSION=JENKINS-26374 jenkins/pct
```

#### Configuration

Environment variables:

* `ARTIFACT_ID` - ID of the artifact to be tested.
This is the only **mandatory** parameter.
The image will be able to determine this ID automatically if `CHECKOUT_SRC` or `/pct/plugin-src` are defined.
* `VERSION` - tag/commit/branch to be checked out and tested. `master` by default
* `CHECKOUT_SRC` - Custom Git clone source (e.g. `https://github.com/oleg-nenashev/job-restrictions-plugin.git`). `https://github.com/jenkinsci/${ARTIFACT_ID}-plugin.git` by default
* `JAVA_OPTS` - Java options to be passed to the PCT CLI
Expand Down
38 changes: 27 additions & 11 deletions src/main/docker/run-pct.sh
Expand Up @@ -15,15 +15,19 @@ fi
###
if [ -n "${ARTIFACT_ID}" ]; then
echo "Running PCT for plugin ${ARTIFACT_ID}"
else
echo "ERROR: Artifact ID is not specified. Use environment variable, e.g. \"-e ARTIFACT_ID=credentials\""
exit -1
fi

if [ -n "${CHECKOUT_SRC}" ] ; then
echo "Using custom checkout source: ${CHECKOUT_SRC}"
else
CHECKOUT_SRC="https://github.com/jenkinsci/${ARTIFACT_ID}-plugin.git"
else
if [ -z "${ARTIFACT_ID}" ] ; then
if [ ! -e "/pct/plugin-src/pom.xml" ] ; then
echo "Error: Plugin source is missing, cannot generate a default checkout path without ARTIFACT_ID"
exit -1
fi
else
CHECKOUT_SRC="https://github.com/jenkinsci/${ARTIFACT_ID}-plugin.git"
fi
fi

if [ -z "${VERSION}" ] ; then
Expand Down Expand Up @@ -53,18 +57,30 @@ fi
###
mkdir -p "${PCT_TMP}/localCheckoutDir"
cd "${PCT_TMP}/localCheckoutDir"
TMP_CHECKOUT_DIR="${PCT_TMP}/localCheckoutDir/undefined"
if [ -e "/pct/plugin-src/pom.xml" ] ; then
echo "Located custom plugin sources"
mkdir "${ARTIFACT_ID}"
cp -R /pct/plugin-src/* "${ARTIFACT_ID}/"
echo "Located custom plugin sources on the volume"
mkdir "${TMP_CHECKOUT_DIR}"
cp -R /pct/plugin-src/* "${TMP_CHECKOUT_DIR}/"
# Due to whatever reason PCT blows up if you have work in the repo
cd "${ARTIFACT_ID}" && mvn clean && rm -rf work
cd "${TMP_CHECKOUT_DIR}" && mvn clean && rm -rf work
else
echo "Checking out from ${CHECKOUT_SRC}:${VERSION}"
git clone "${CHECKOUT_SRC}"
mv $(ls .) ${ARTIFACT_ID}
cd ${ARTIFACT_ID} && git checkout "${VERSION}"
mv $(ls .) ${TMP_CHECKOUT_DIR}
cd ${TMP_CHECKOUT_DIR} && git checkout "${VERSION}"
fi

###
# Determine artifact ID and then move the project to a proper location
###
cd "${TMP_CHECKOUT_DIR}"
if [ -z "${ARTIFACT_ID}" ] ; then
ARTIFACT_ID=$(mvn org.apache.maven.plugins:maven-help-plugin:2.2:evaluate -Dexpression=project.artifactId | grep -Ev '(^\[|Download.*)')
echo "ARTIFACT_ID is not specified, using ${ARTIFACT_ID} defined in the POM file"
mvn clean
fi
mv "${TMP_CHECKOUT_DIR}" "${PCT_TMP}/localCheckoutDir/${ARTIFACT_ID}"

###
# Run PCT
Expand Down

0 comments on commit 1d20f1c

Please sign in to comment.